I'm trying to run a Django management command via a crontab installed to /etc/cron.d/mycron on Ubuntu.
I first tested my basic setup by writing the following to /etc/cron.d/mycron:
* * * * * root command echo "Test $(date)" 2>&1 >> /tmp/mycron.log
And I confirmed /tmp/mycron.log was updated once a minute and contains the expected text.
I then tried the following variations using my actual management command:
* * * * * root command python /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
* * * * * root command /usr/bin/python /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
* * * * * root command /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
* * * * * python /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
* * * * * /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
* * * * * /usr/bin/python /path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log
And even though the log file is generated, it contains none of the expected logging text my management command outputs.
After each variation, I run sudo touch /etc/cron.d/ to reload cron. Even if there was an error in my Python code, I'd expect some sort of error message to get logged.
I've checked tail -f /var/log/syslog, and the only errors it shows are for crontabs that don't start with "root", for which it gives me the error:
Error: bad username; while reading /etc/cron.d/mycron
For all the others, I see something like:
Oct 7 10:54:01 localhost CRON[27805]: (root) CMD (/path/to/my/script/manage.py mycommand 2>&1 >> /tmp/mycron.log)
But nothing's written to the log, and the database changes I expect to happen aren't occuring. What am I doing wrong?