Django management command not found by cron
I made a management app imaginitively called update
. The following work fine from the command line:
./manage.py update
/full/path/manage.py update
But when I have the following cron command:
00 */3 * * * /websites/bnc/manage.py update >/dev/null
It emails me this error:
Unknown command: 'update'
开发者_开发百科Type 'manage.py help' for usage.
It smells like a path issue but I can't see how because I can call it manually from wherever. Any idea what's going on here?
I had the same exact problem and found the solution, you need to be int he correct directory to run the Django management commands.
For your example, you'll need to update your crontab like so:
00 */3 * * * cd /websites/bnc && ./manage.py update >/dev/null
Works like a charm. I'm not sure why, but adding this directory to my PYTHONPATH inside the command didn't work for me, but the above worked like a charm.
The environment is likely not the same, so PYTHONPATH/PATH are not set. It might fail to find import django (or python/lib/site-packages).
I'm doing something similar. Try prefacing /websites/bnc/manage.py
in your crontab with a PYTHONPATH=...
精彩评论