[英]python script does not run from cron
I have a python script "start.py" that executes well from the command line.我有一个从命令行很好地执行的 python 脚本“start.py”。 There is only one statement in it (print "hello").其中只有一个语句(打印“hello”)。 EDIT: start.py contains also a working interpreter directive in the first line.编辑: start.py 在第一行还包含一个工作解释器指令。
As soon as I run the script from a cron job, every time it fires there is a message in syslog:一旦我从 cron 作业运行脚本,每次触发时,系统日志中都会出现一条消息:
Jun 7 02:57:01 mit CRON[23275]: Module is unknown
I tried already to add PATH and PYTHONPATH information to the cron file:我已经尝试将 PATH 和 PYTHONPATH 信息添加到 cron 文件中:
$ cat /etc/cron.d/my_cron
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PYTHONPATH=/usr/lib/python2.6:/usr/lib/python2.6/plat-linux2:/usr/lib/python2.6/lib-tk:/usr/lib/python2.6/lib-old:/usr/lib/python2.6/lib-dynload:/usr/lib/python2.6/dist-packages:/usr/lib/pymodules/python2.6:/usr/lib/pymodules/python2.6/gtk-2.0:/usr/local/lib/python2.6/dist-packages
* * * * * mit /home/mit/dev/start.py
I found several answers and solutions that seem the same but nothing helped me.我找到了几个看起来相同但没有任何帮助的答案和解决方案。 What am I missing?我错过了什么?
A recent update of PAM broke cron. PAM 的最新更新破坏了 cron。 Try restarting your computer (or restarting cron with sudo /etc/init.d/cron restart
)尝试重新启动计算机(或使用sudo /etc/init.d/cron restart
启动 cron)
You forgot to add python in front of it.您忘记在它前面添加 python。
* * * * * mit /usr/bin/python /home/mit/dev/start.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.