开发者

Django/Python How should this cronjob be executed

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    *    * 开发者_如何学Go   *    cd /www/site/mydirectory;python perform_daily_action.py

Although this does not seem to work.

Suggestions?


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.


Try use this instead

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜