Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a cron task as

6,36 * * * * python /usr/local/news.py >> /var/log/newlog

it is supposed to run at every 6th and 36th minute of each hour.

But for some how the system runs this task 4 processes/times each time. This task is to update database, and it causes problem when three processes updating database at the same time.

I have 4 tasks listing in /var/spool/cron/root, this is one of the tasks

What possibly went wrong here?

Thanks

Edit:

Oct 9 20:06:01 online CROND[7882]: (root) CMD (python /usr/local/news.py >> /var/log/newslog)  
Oct 9 20:06:01 online CROND[7883]: (root) CMD (python /usr/local/news.py >> /var/log/newslog)  
Oct 9 20:06:01 online CROND[7888]: (root) CMD (python /usr/local/news.py >> /var/log//newslog)  
Oct 9 20:06:01 online CROND[7890]: (root) CMD (python /usr/local/news.py >> /var/log//newslog)
share|improve this question
    
What does your log say? –  Dennis Williamson Oct 10 '09 at 2:02
    
I mean /var/log/cron.log rather than the one in the crontab line above. –  Dennis Williamson Oct 10 '09 at 2:04
    
Oct 9 20:06:01 online CROND[7882]: (root) CMD (python /usr/local/news.py >> /var/log/newslog) Oct 9 20:06:01 online CROND[7883]: (root) CMD (python /usr/local/news.py >> /var/log/newslog) Oct 9 20:06:01 online CROND[7888]: (root) CMD (python /usr/local/news.py >> /var/log//newslog) Oct 9 20:06:01 online CROND[7890]: (root) CMD (python /usr/local/news.py >> /var/log//newslog) –  Weiwei Oct 10 '09 at 3:28
    
4 lines of "Oct 9 20:06:01 online CROND[7890]: (root) CMD (python /usr/local/news.py >> /var/log//newslog)" running at the same time, now sure what is going on –  Weiwei Oct 10 '09 at 3:29
    
FYI: I have 4 tasks listing in /var/spool/cron/root –  Weiwei Oct 10 '09 at 3:49

3 Answers 3

up vote 1 down vote accepted

What is the result of the following command? If there is more than one number listed then cron is running more than once which could cause this problem.

pgrep -l cron
share|improve this answer
    
3674 crond 6335 crond 20785 crond 22084 crond –  Weiwei Oct 10 '09 at 14:27
    
i have this output when i run pgrep -l cron " 3674 crond 6335 crond 20785 crond 22084 crond " It looks i have 4 copies of crond are running at the same time? –  Weiwei Oct 10 '09 at 14:30
    
Thanks! i think problem should be gone (after i rebooted my server). For somehow I have 4 instances of crond running at the same time. –  Weiwei Oct 10 '09 at 14:41

By 'I have 4 tasks listing in /var/spool/cron/root', do you mean:

'I have 4 lines in root's crontab, all the same thing.'?

Please paste the output of 'crontab -l'. If it looks anything like:

6,36 * * * * python /usr/local/news.py >> /var/log/newlog
6,36 * * * * python /usr/local/news.py >> /var/log/newlog
6,36 * * * * python /usr/local/news.py >> /var/log/newlog
6,36 * * * * python /usr/local/news.py >> /var/log/newlog

That's definitely the problem :0

share|improve this answer
    
sorry, no i have for different tasks. the one 6,36 * * * * python /usr/local/news.py >> /var/log/newlog is only one of them –  Weiwei Oct 10 '09 at 4:15
    
In that case, you don't happen to have started 4 instances of crond somehow, have you? Is this the only task that runs 4 copies at the same time, or do all tasks do so? Also, please paste the output of 'crontab -l' into your question. –  MikeyB Oct 10 '09 at 4:23

It looks like two of the runs have a slightly different syntax. Could you check /etc/crontab and /etc/cron.d to check you don't have copies of the command there?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.