Django/Python How should this cronjob be executed

隐身守侯 提交于 2020-01-16 19:17:10

问题


I created a simple python script that allows me to update a chosen animal to be displayed on the sites frontpage.

when I am in my ssh, I run it like this.

cd /www/site/mydirectory
python perform_daily_action.py

How do I run this in my crontab as a cronjob.

I tried to do

30    09    *    *    *    cd /www/site/mydirectory;python perform_daily_action.py

Although this does not seem to work.

Suggestions?


回答1:


Try use this instead

30    09    *    *    *    python /www/site/mydirectory/perform_daily_action.py



回答2:


The other answers are great, I would only suggest using full path also for Python interpreter, because cron environment might be different than the regular one and also at some point you might want to switch to virtualenv and then you will definitely need Python interpreter from virtualenv folder.




回答3:


You must provide the full python location (for example /usr/bin/python) and/or perhaps give your machine some guidelines about your $PYTHONPATH. Try this:

30    09    *    *    * export PYTHONPATH=/www/site/mydirectory:.:$PYTHONPATH && /usr/bin/python /www/site/mydirectory/perform_daily_action.py


来源:https://stackoverflow.com/questions/5455425/django-python-how-should-this-cronjob-be-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!