Crontab fails to execute Python script

喜夏-厌秋 提交于 2019-11-28 12:14:31

The main.py script calls some methods from other modules under python_prj, does that matter?

Yes, it does. All modules need to be findable at run time. You can accomplish this in several ways, but the most appropriate might be to set the PYTHONPATH variable in your crontab.

You might also want to set the MAILTO variable in crontab so you get emails with any tracebacks.

[update] here is the top of my crontab:

www:~# crontab -l

DJANGO_SETTINGS_MODULE=djangocron.settings
PATH=...
PYTHONPATH=/home/django
MAILTO="cron-notices@example.com"
...
# m h  dom mon dow   command
10-50/10 * * * *               /home/django/cleanup_actions.py
...

(running cleanup actions every 10 minutes, except at the top of the hour).

user3229464

Any file access in your scripts? And if so, have you used relative paths (or even: no explicit path) in your script?
When run from commandline, the actual folder is 'your path', where you start the script from. When run by cron, 'your path' may be different depending on environment variables.
So try using absolute paths to any files you access.

Check the permissions of the script. Make sure that it's executable by cron-- try chmod +x main.py.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!