Search code examples
cron

Crontab syntax for non-aligned hourly range?


If I want to schedule a job to occur every five minutes between 9 until 11 pm I can use the following cron trigger:

0/5 21-22 * * *

(or something like 5,10,15,20,25,30,35,40,45,50,55 21-22 * * * for finer control over the minutes if needed).

Is there a way to specify "every five minutes from 9:30 until 11:30"? The trickiness revolves around having e.g. 5 in the minutes field yet skipping it if the hour is 21, and I'm not immediately aware of any way to achieve that.


Solution

  • A simple, workaround would be to add more scheduled jobs in cron...

    i.e.

    30,35,40,45,50,55 21 * * *  /job_to_run
    */5 22 /job_to_run
    5,10,15,20,25,30 23 * * * /job_to_run
    

    p.s. Cron usually has the following order:

    Minutes Hour DayOfMonth Month DayOfWeek Command