Crontab often call some programs, but many times it is unsuccessful to call Python, but the manual is ok, when looking at the log (/var/log/cron) , but the display is normal, this situation how to break it? In fact, there are so many places:
1) Easily do not use if __name__ = = "__main__";
Many executives are accustomed to let their people write scripts into modular, and then take a graceful integration, but crontab to this method does not seem very bright, because Python runs from if __name__ = = "__main__" to start execution, And the above of those class crontab recognition is very laborious, but can only recognize function, and originally crontab is placed is some watchdog script, so write as much as possible, format not too complex.
2) note in English and Chinese, this is a hidden pit point, some crontab logs show that the script executes successfully, but the result is redirected to a file found in fact there is a problem of coding error;
3) Write absolute path, if it is Yum installation, write/usr/bin/python, if it is a custom installation, write the full path, script file also write absolute path;
4) Some Python scripts need to involve the database, but sometimes crontab cannot find the specific database, this time need to reset the environment variables such as Wow_path before the Python script execution, such as
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/FA/wKiom1flE5-D8hDdAAAmC3PdRhE748.png "title=" 111. PNG "alt=" Wkiom1fle5-d8hddaaamc3pdrhe748.png "/>
5) If none of the above works, then add Source/etc/profile to the crontab, as follows:
Absolute path to source/etc/profile && python py script
This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1855941
Crontab The Python script is not a successful solution