Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this cron entry executed twice?

Tags:

*/5 * * * * my command 

This entry works but every 5 minutes it gets executed twice, why?

In /var/log/cron it shows:

Jun 16 22:20:01 Test CROND[12512]: (root) CMD (my command) Jun 16 22:20:01 Test CROND[12516]: (root) CMD (my command) 

So it's not from two users.

It is only entered once with crontab -e -u root. The command is a php command.

like image 885
erotsppa Avatar asked Jun 17 '09 02:06

erotsppa


People also ask

How do I stop a cron job run twice?

Methods of preventing duplicates The first technique is a lock file. A common implementation of this is to simply check if a file exists, if it does, stop the job execution. If the file does not exist, than create it and continue executing the job. The second technique is a PID file or Process ID file.

What does cron 0 * * * * * mean?

*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.

What is the use of * * * * * In cron?

* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.

How do I stop a cron job execution?

Stop a cron job You can stop a single cron job by removing its line from the crontab file. To do that, run the crontab -e command and then delete the line for the specific task. Alternatively, you can stop the cron job by commenting it out in the crontab file.


2 Answers

Nothing in the description gives reason for it to be executed twice. Look elsewhere.

  • Do two users call it?
  • Is it entered twice?
  • Does it call itself?
  • Does it set in motion conditions for repetition?

If it's a shell script you're executing, have it append whoami and date to a log file. You should be able to dig up the reason.

UPDATE

Type ps -A | grep crond, make sure crond isn't running twice.

like image 114
Stefan Mai Avatar answered Oct 21 '22 15:10

Stefan Mai


The wget in crontab has often a limit of 15 minutes. In our case this was just the case, and after those 15 minutes the job ends up with a timeout and then re-runs again right away. So, the solution to this was to set up the cronjob in crontab somewhat like this :

1 2 * * * root wget --read-timeout=3600 -O - 'http://cron-job-url' >/dev/null 2>&1 

...instead of

 1 2 * * * root wget -O - 'http://cron-job-url' >/dev/null 2>&1 

So, wget is the thing. Meaning 3600 = 1 hour then. Or more if you need!

like image 45
anoraq Avatar answered Oct 21 '22 14:10

anoraq