I am looking to schedule a cron from 10PM to 1AM(both inclusive) every half an hour .
I tried this */30 22-0 * * *
doesn't seem to work after 11:30 PM
or to be specific this works till 11:59 PM I guess.
I am looking to schedule a cron from 10PM to 1AM(both inclusive) every half an hour .
I tried this */30 22-0 * * *
doesn't seem to work after 11:30 PM
or to be specific this works till 11:59 PM I guess.
Cron doesn't always provide the syntax to specify the times you want in a single line, but there's usually a workaround using two lines (or sometimes more).
Based on your description, apparently a range whose upper bound is smaller than its lower bound doesn't wrap around; rather it just seems to extend to the end of the day/hour/whatever. In your case, 22-0
apparently represents hours 22
and 23
, and presumably 22-5
, for example, would mean the same thing. (The man page is unclear on this.)
This should do the trick, though I haven't had a chance to test it:
*/30 22-23 * * * <command> # 22:00, 22:30, 23:00, 23:30
*/30 0 * * * <command> # 00:00, 00:30
0 1 * * * <command> # 01:00
Based on the other answer: You can make the crons one line less by combine records for 22-23 and 0 hour:
*/30 0,22-23 * * * <command>
0 1 * * * <command>
In some UNIX operating systems this may not work and you should explicitly mention the hours and minutes:
0,30 0,22,23 * * * <command>
0 1 * * * <command>