Cron – What does “every two minutes” mean in cron

cron

I've got two scripts in cron set to run every two minutes: */2 — the thing is, they're out of step. One runs at 1,3,5,7,9 minutes, etc. and the other at 0,2,4,6,8. This is not a mission-critical problem, but means I've got two status reports, one a bit stale compared to the other.

What does cron do exactly? Run the first one in crontab document order, waiting till it's finished to run the second one?

Is there any way I can make the run at the same time, or as close as possible?

Best Answer

The job will be run as close to the given time as possible, but may be run slightly later. As Chris suggested, the best thing to do is probably create a small shell script and schedule that instead:

#!/bin/sh
/path/to/job/one &
/path/to/job/two &

In this case I started them in the background to ensure they both run at or nearly at the same time, but depending on your system, your requirements, etc., you will have to adjust this to suit your needs.

Also note that on some systems */2 doesn't actually mean only times divisible by 2, but reoccur in steps equal to 2. So, if the job time matches a 1 when the job is initially started, it may run then every odd minute, as you're seeing, rather than every even one. You could try something like:

00-58/2

to force the job to start on even instances only, but whether and how this works is really dependent on your system, your version of the cron daemon, etc. To get more detailed help, you would have to supply this information :)

Related Topic