Cron Expression for Every 2 Hours
The cron expression for "every 2 hours", what each field means, and the next run times on your clock.
What is the cron expression for every 2 hours? The cron expression for every 2 hours is 0 */2 * * *. The hour field steps by 2, so the job runs at 00:00, 02:00, 04:00 and every even hour through 22:00, 12 times a day. The 0 in the minute field matters: leave it as * and the job runs every minute of those hours.
0 */2 * * *On the hour, every 2 hours
- …
- …
- …
- …
- …
Why does * */2 * * * run 720 times a day?
Because the minute field is still a wildcard. * */2 * * * matches every minute of every even hour: 60 runs in the 00:00 hour, 60 in the 02:00 hour and so on, 720 a day instead of 12. The expression is valid, so nothing warns you until the job floods its log. Pin the minute to one value and the schedule drops back to one run every 2 hours.
That value doesn't have to be 0. 30 */2 * * * keeps the 2-hour gap and runs at 00:30, 02:30 and so on. A minute step can't reach 2 hours at all, because the minute field only counts 0 to 59: our generator warns that */120 would run only at minute 0, which is an hourly job.
How do you run every 2 hours on odd hours or during the working day?
Start the step from an odd hour. 0 1-23/2 * * * runs at 01:00, 03:00 and every odd hour through 23:00. The crontab man page gives 0-23/2 as the long form of every other hour and */2 as the short one, so changing where the range starts shifts the whole schedule.
To keep it inside the working day, narrow the range: 0 9-17/2 * * * runs at 09:00, 11:00, 13:00, 15:00 and 17:00, and 1-5 in the last field limits it to weekdays. Because 2 divides 24 evenly, the gap from 22:00 to 00:00 is also 2 hours. Steps that don't divide 24 break at midnight: cron evaluates steps within one calendar day, so 0 */5 * * * runs at 20:00 and then at 00:00, only 4 hours later.
Frequently asked
What does 0 */2 * * * mean?
At minute 0 of every second hour: 00:00, 02:00, 04:00 and so on to 22:00, every day of the year. That is 12 runs in 24 hours, in the time zone the scheduler uses.
How do I run every 2 hours starting at a specific time?
Start the hour range there. 0 1-23/2 * * * starts at 01:00. 15 8-23/2 * * * starts at 08:15, runs every 2 hours until 22:15, then waits until 08:15 the next day.
Is */2 the same as 0-23/2 in the hour field?
Yes. The crontab man page lists 0-23/2 as the range form and */2 as the shorthand, and both match hours 0, 2, 4 and on to 22. It also gives the long list form, 0,2,4,6,8,10,12,14,16,18,20,22.