python 脚本不从 cron 运行
我有一个 python 脚本“start.py”,可以从命令行很好地执行。其中只有一条语句(打印“hello”)。编辑:start.py 在第一行还包含一个工作解释器指令。
一旦我从 cron 作业运行脚本,每次触发时,系统日志中都会出现一条消息:
Jun 7 02:57:01 mit CRON[23275]: Module is unknown
我已经尝试将 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 have a python script "start.py" that executes well from the command line. There is only one statement in it (print "hello"). EDIT: start.py contains also a working interpreter directive in the first line.
As soon as I run the script from a cron job, every time it fires there is a message in syslog:
Jun 7 02:57:01 mit CRON[23275]: Module is unknown
I tried already to add PATH and PYTHONPATH information to the cron file:
$ 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PAM 最近的更新破坏了 cron。尝试重新启动计算机(或使用
sudo /etc/init.d/cron restart
重新启动 cron)A recent update of PAM broke cron. Try restarting your computer (or restarting cron with
sudo /etc/init.d/cron restart
)你忘了在它前面添加 python 。
You forgot to add python in front of it.