In the http://chenx1242.blog.51cto.com/10430133/1884415 wrote a monitoring MQ script, the script into the crontab to monitor the time, so #crontab- e, To add a statement:
* * * * * CD/directory && python MQ script name. PY >/root/mq.log 2>&1
Send the results of the execution to the/root/mq.log, and open a look inside to see that the error has occurred:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/94/AE/wKiom1kMKxnz8iaZAACRhozHUls666.png "title=" 1.png "alt=" Wkiom1kmkxnz8iazaacrhozhuls666.png "/>
But in the shell alone execution is OK, so add source/etc/profile or error, visible is not the problem of environment variables, how to do?
First,#which pythonto determine the path to Python:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/94/AE/wKiom1kMLEfQAQ5OAAAPfClEhe0780.png "title=" 1.png "alt=" Wkiom1kmlefqaq5oaaapfclehe0780.png "/>
The entire Python path is copied into the crontab, the whole #crontab-l effect is like this:
* * * * * * source/etc/profile && CD/directory && nohup/usr/local/bin/python MQ script name. PY >/root/mq.log 2>& ; 1
If more than one version of Python is installed on a machine, it is more about specifying the path to Python, or crontab will be foolish enough to find the default path.
This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1922450
crontab importerror:no module named XXX occurs when calling Python