Monday, July 12, 2010

crontab for every X minutes excluding a period Y hours

Crontab isnt really hard its just limited.

To execute for every 5 minutes except between 1:00 to 2:00
*/5 0-1,2-23 * * * /bin/hello.sh

If you need finer control than an hour you might need to consider using 2 lines;
*/5 0-1,2-23 * * * /bin/hello.sh
0,5,10,55 1-2 * * * /bin/hello.sh

1 comment:

  1. If you put examples only you should at least make sure that you're right. From what I read on the crontab manpage, the dash includes the whole range:

    The dash (-) operator specifies a range of values, for example: "1-6", which is equivalent to "1,2,3,4,5,6"

    So as for the hours in the first example, 0-1,2-23, it will run at 0,1,2,3,4,5,etc... no timegap there ;)

    ReplyDelete