Cron job running a Django Python command through a virtual environment not working
There are a couple of ways to solve this:
First, it doesn't work because /bin/sh
is the shell cron uses to run commands, but /bin/sh
doesn't support source
. So the quick fix is to set SHELL=/bin/bash
in the crontab.
Or...
Second, it's not necessary to source virtualenv/bin/activate
anyway. You can just call the virtualenv python directly.
* * * * * cd /home/www/production/mydjangoproject; /home/virtualenvs/mydjangoproject-venv/bin/python manage.py mydjangocommand
These were taken from this question on SO, the answers to which may contain other ideas for people in similar but not quite the same circumstances.