Running a cron job at different frequencies throughout the day

Is it possible to run a cron job for different frequencies throughout the day? Or to achieve the same effect, is it possible to run a cron job at a regular frequency, but only at certain hours of the day?

Example I would like to run my script 6 / hour between 11:00 - 14:00 and 6 / hours between 17:00 and 20:00. Otherwise, I would like the script to run 1 / hour.

+3


source to share


1 answer


You can, for example, use:

*/10 11-13,17-19   * * * /your/script  # every 10 min 11.00 to 13.00, 17.00 to 19.00
0 0-10,14-16,20-23 * * * /your/script  # every 1 hour 00.00 to 10.00, 14.00 to 16.00, 20.00 to 23.00

      

  • */10 11-13,17-19 * * *

    means: every 10 minutes in hours from 11 to 13 and from 17 to 19. That is, between 11.00 and 13.59 and 17.00 and 19.59.
  • 0 0-10,14-16,20-23 * * *

    means: every minute 0

    in hours from 0 to 10, from 14 to 16 and from 20 to 23. That is, exactly the hours are 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 14, 15 , 16, 20, 21, 22, and 23 (all except 11, 12, 13, 17, 18, and 19).



Remember that the format looks like this:

 +---------------- minute (0 - 59)
 |  +------------- hour (0 - 23)
 |  |  +---------- day of month (1 - 31)
 |  |  |  +------- month (1 - 12)
 |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
 |  |  |  |  |
 *  *  *  *  *  command to be executed

      

+5


source







All Articles