Root Cron to run Python

I was having some issues with a cron job I created as root using crontab -e
the entry was: */15 * * * * /path/to/file.py
After ripping my hair out overnight (Troubleshooting tips):

tail /var/log/cron (checks if it is running)
add a line to your crontab: MAILTO=”you@domain.com” – will email you debugging info

Here’s the solution:

Wrap the calling of python in shell and set up the environment first.

Modify the crontab entry to:
*/15 * * * * /bin/csh /path/to/fileWrapper.sh

#!/bin/csh
setenv PATH /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin:${PATH}
/usr/local/bin/python2.7 /usr/local/bin/updater.py

Leave a Reply

Your email address will not be published. Required fields are marked *