How to run in crontab
*/1 * * * * /home/user/Desktop/job/dp/ python manage.py statistics
with virtual env? I need to activate virtualenv first(Otherwise it does not work)
This is my virtual env:
source job/bin/activate
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDITED:
Try something like this:
This should be read as: activate the env and if that was successful, excute the manage.py script. Since manage.py is supposed to have a python shebang and the virtual env sets the correct python interpreter, this should work.
Apparently cron usually runs with
/bin/shwhich does not know thesourcecommand. So one option is to use a dot as asourcereplacement. Another to set/bin/bashin the cron file:Read more about this issue at:
http://codeinthehole.com/writing/running-django-cronjobs-within-a-virtualenv/
The article doesn’t mention that
sourcecan be replaced by a., but i’ve just tried it and it worked for me. So you have several options to choose from now, the article even has others. 😉