*/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.
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.
*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.
* * * * * 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.
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.
Nothing in the description gives reason for it to be executed twice. Look elsewhere.
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.
Type ps -A | grep crond
, make sure crond isn't running twice.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With