开发者

Crontab job does not start... ideas?

thanks for helping me setting my cron jobs, crontab has really been a gold mine for me.

Unfortunately I have a problem, and have no idea what so ever what it might be... basically a job does not start while the neighbour jobs do. I'll explain


This is my crontabs job list:

*/10 * * * * python /webapps/foo/manage.py fetch_articles

*/10 * * * * python /webapps/bar/manage.py fetch_books

I wrote them as they are in a file and stored them 开发者_如何学Pythonusing crontab /path/to/file .

Checked with crontab -l and the jobs are there.


The strange thing is that 1 of these executes every 10 minutes normally... but the other one does not. I tried typing in the command manually, and it works fine without a problem.


Does anyone have suggestions?

Help would be much appreciated, thanks guys.


Update:

I've been in the system log files and I found this:

Mar 5 02:50:01 localhost CRON[21652]: (root) CMD (python /webapps/foo/manage.py fetch_books)

Does this mean crontab is calling the job fine?


Thanks for your replies guys!


FIXED IT! thank you very much everyone!!

The problem was that the script silently failed, I believe it's due to the PYTHON_PATH changing due to where the script is called from... I'm entirely sure.


Cron always runs in an environment different to what you think :-)

I always have my cronjobs set up like:

*/10 * * * * ( date ; python /webapps/foo/manage.py fetch_articles ) >>/tmp/fetch.out 2>&1

to ensure that there's something logged that I can look at.

This will narrow your problem down to either:

  • cron, if the temp file doesn't appear; or
  • your script, if it does appear.

And, in the latter case, hopefully there'll be some output you can debug. If not, put output in there.

One way to do that is to put:

set -x

at the top of the script which will cause all lines to be output before execution. All of my scripts tend to start:

#!/bin/bash
#set -x

so I can just uncomment that second line while debugging.


From the crontab manpage:

BUGS Although cron requires that each entry in a crontab end in a newline character, neither the crontab command nor the cron daemon will detect this error. Instead, the crontab will appear to load normally. However, the command will never run. The best choice is to ensure that your crontab has a blank line at the end.

(my emphasis).


I think ~unutbu's answer is probably correct if it's the second job that isn't running.

However another thing to check is whether /webapps/bar/manage.py requires exclusive access to any resources, eg network sockets/tempfiles etc. Since you are starting 2 processes at the same time, you may be triggering a race condition.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜