ttemple
ttemple

Reputation: 1985

How to create a cronjob that runs every 5 minutes from 8:30 AM to 9:30 PM?

I am trying to run a cron job every 5 minutes from 8:30 AM to 9:30 PM. I've been searching around the web and here is what I came up with:

    30,35,40,45,50,55  8 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
    */5  9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
    5,10,15,20,25,30 22 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1

I have looked at cron job generators but they do not seem to address the requirement to start/end on the half-hour. Does anyone have a better or more concise solution?

Upvotes: 5

Views: 7227

Answers (2)

MSRK
MSRK

Reputation: 5

30-59/5 8-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
00-25/5 9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1

would serve the purpose.

Upvotes: 0

Michel
Michel

Reputation: 2623

30-59/5  8    * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
*/5      9-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
0-30/5   21   * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1

should also work, and easier to read.

Upvotes: 11

Related Questions