6

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)
rkthkr
  • 8,618
  • 28
  • 38
Weiwei
  • 367
  • 1
  • 5
  • 10
  • What does your log say? – Dennis Williamson Oct 10 '09 at 02:02
  • I mean /var/log/cron.log rather than the one in the crontab line above. – Dennis Williamson Oct 10 '09 at 02: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 03: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 03:29
  • FYI: I have 4 tasks listing in /var/spool/cron/root – Weiwei Oct 10 '09 at 03:49
  • You should post follow-ups with listings like that as an edit of your answer. Then you can use quote block formatting to make it more readable. I'll take care of it for you. – Dennis Williamson Oct 10 '09 at 04:21
  • "now sure what is going on" - **now** sure or **not** sure? – Dennis Williamson Oct 10 '09 at 04:26
  • Please take a few minutes to correct your many typos - your mistakes are making assisting you difficult. For example, according to the lines from syslog that you pasted, you have two similar but different commands running. – MikeyB Oct 10 '09 at 04:34

3 Answers3

1

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

MikeyB
  • 39,291
  • 10
  • 105
  • 189
  • 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 04: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 04:23
1

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
emills
  • 774
  • 1
  • 4
  • 15
  • 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
1

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?

Douglas Leeder
  • 2,745
  • 18
  • 15