Crond offset five minute schedule

Solution 1:

The minute entry field for crontab accepts an "increments of" operator that is kind of confusing because it looks like it should be a mathematical "divide by" operator but isn't. You will most often see it used something like the following. Note that this does not find numbers that are divisible by five but rather takes every fifth item from a set:

 */5 * * * * command

This tells cron to match every fifth item (/5) from the set of minutes 0-59 (*) but you can change the set like this:

 1-59/5 * * * * command

This would take every fifth item from the set 1-59, running your command at minutes 6, 11, 16, etc.

If you need more fine grained offsets than one minute, you can hack it using the sleep command as part of your crontab like this:

 */5 * * * * sleep 15 && command

This would run your job every five minutes, but the command would not actually start until 15 seconds after the minute. For short running jobs where being a few seconds after something else makes all the difference but you don't want to be a full minute late, this is a simple enough hack.

Solution 2:

You can run scripts whenever you want using cron. If you want to run script 1 every 5 minutes, you might start like this:

*/5 * * * * /path/to/script1

But this is really just shorthand for:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/script1

If you want to run script 2 one minute after script 1, you can do this:

1,6,11,16,21,26,31,36,41,46,51,56 * * * * /path/to/script2

You could also do this:

*/5 * * * * /path/to/script1
*/5 * * * * /path/to/script2

And then at the start of script 2, sleep for one minute:

sleep 60

Solution 3:

You can indicate a time offset with the + symbol. For example, to run at :01, :06, :11, :16 [...], create a task such as

*/5+1 * * * * command

Solution 4:

This worked for me:

1/5 * ? * * *

Where 1 is the offset minutes. So if you want to offset three minutes:

3/5 * ? * * *

I have this working in AWS schedule settings

Tags:

Cron