crontab fails to execute a Python script. The command line I am using to run the Python script is ok.
These are solutions I had tried:
- add
#!/usr/bin/env pythonat the top of themain.py - add
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/binat the top ofcrontab chmod 777to themain.pyfileservice cron restart
my crontab is:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
*/1 * * * * python /home/python_prj/main.py
and the log in /var/log/syslog is:
Nov 6 07:08:01 localhost CRON[28146]: (root) CMD (python /home/python_prj/main.py)
and nothing else.
The main.py script calls some methods from other modules under python_prj, does that matter?
Anyone can help me?
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:
(running cleanup actions every 10 minutes, except at the top of the hour).