Run Cron job every N minutes plus offset

后端 未结 3 830
既然无缘
既然无缘 2020-11-28 18:00

*/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

相关标签:
3条回答
  • 2020-11-28 18:09

    Sure!

    5,25,45 * * * * /your/cron
    
    0 讨论(0)
  • 2020-11-28 18:11

    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.

    0 讨论(0)
  • 2020-11-28 18:29

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

    0 讨论(0)
提交回复
热议问题