284
votes

*/20 * * * *

Ensures it runs every 20 minutes, I'd like to run a task every 20 minutes, starting at 5 past the hour, is this possible with Cron? Would it be:

5/20 * * * * ?

3
Thanks the Babylonians, who decided that our time system should be exactly divided by 1,2,3,4,5 and 6.arivero
if it's divisible by 2 and 3 it's also divisible by 6Ziofil

3 Answers

579
votes

To run a task every 20 minutes starting at 5 past the hour, try this:

 5-59/20 * * * *

Explanation

An * in the minute field is the same as 0-59/1 where 0-59 is the range and 1 is the step. The command will run at the first minute in the range (0), then at all successive minutes that are distant from the first by step (1), until the last (59).

Which is why */20 * * * * will run at 0 minutes, 20 minutes after, and 40 minutes after -- which is the same as every 20 minutes. However, */25 * * * * will run at 0 minutes, 25 minutes after, and 50 minutes after -- which is not the same as every 25 minutes. That's why it's usually desirable to use a step value in the minute field that divides evenly into 60.

So to offset the start time, specify the range explicitly and set the first value to the amount of the offset.

Examples

5-59/20 * * * * will run at 5 minutes after, 25 minutes after, and 45 minutes after.

10-59/25 * * * * will run at 10 minutes after and 35 minutes after.

1-59/2 * * * * will run every odd minute.

67
votes
15
votes

You can try: */5 * * * * sleep N; your job