Skip to content
Cron Cookbook

Run a job every 2 hours

The cron expression for every 2 hours is 0 */2 * * *. The */2 step in the hour field fires at 00:00, 02:00, 04:00 and every even hour through 22:00, 12 times a day. Keep the 0 in the minute field: * */2 * * * runs every minute during those hours.

crontab syntax · 5 fields
0*/2***

Next 5 runs

Vercel always runs schedules in UTC, and GitHub Actions does unless you set a time zone. Crontab and Kubernetes use the server's time zone.

Field by field

0Minute
At minute 0
*/2Hour
Every 2nd hour: 0, 2, 4 … 22
*Day of month
Every day of the month
*Month
Every month
*Day of week
Every day of the week

By platform

Most schedulers take the same five fields. The wrapper, time zone and limits differ.

crontab -e
# m h  dom mon dow   command
0 */2 * * * /usr/local/bin/sync.sh >> /var/log/sync.log 2>&1

Runs in the server's local time zone

Cron starts jobs with a minimal environment: use absolute paths, and send output to a log so failures don't disappear.

Other 2-hour schedules

The step counts from midnight, not from when the job was installed. Start the range at 1 for odd hours, or change the minute to move runs off the hour.

ExpressionRuns
0 0,2,4,6,8,10,12,14,16,18,20,22 * * *Same as 0 */2 * * *, with the hours listed
0 1-23/2 * * *Every 2 hours on the odd hours, 01:00 through 23:00
30 */2 * * *Every 2 hours at half past, 00:30 through 22:30
0 8-18/2 * * 1-5At 08:00, 10:00, 12:00, 14:00, 16:00 and 18:00, Monday through Friday

Every 3, 4, 6, 8 or 12 hours

Change the step to change the interval. Each of these divides 24, so the runs stay evenly spaced across midnight. Keep a fixed minute (here 0) in the first field, as for every 2 hours.

IntervalExpressionRunsStarting later
Every 3 hours0 */3 * * *8 a day: 00:00, 03:00, 06:00 … 21:000 1-23/3 * * *
Every 4 hours0 */4 * * *6 a day: 00:00, 04:00, 08:00 … 20:000 2-23/4 * * *
Every 6 hours0 */6 * * *4 a day: 00:00, 06:00, 12:00, 18:000 3-23/6 * * *
Every 8 hours0 */8 * * *3 a day: 00:00, 08:00, 16:000 6-23/8 * * *
Every 12 hours0 */12 * * *2 a day: 00:00 and 12:000 6,18 * * *

The last column shifts the same interval off midnight: 0 2-23/4 * * * runs at 02:00, 06:00, 10:00, 14:00, 18:00 and 22:00. Every 12 hours can also be written with the hours listed, as 0 0,12 * * *.

A step that doesn't divide 24 leaves a short gap at midnight, because the count starts again at 00:00 each day: 0 */5 * * * runs at 00:00, 05:00, 10:00, 15:00 and 20:00, then 4 hours later at midnight, and 0 */7 * * * runs at 00:00, 07:00, 14:00 and 21:00, then 3 hours later. For an exact interval like that, write one line per start time, as for every 90 minutes. On AWS EventBridge, rate(4 hours) counts from when the rule was created instead; the clock-aligned form is cron(0 0/4 * * ? *).

Every 2 hours in Jenkins, Quartz, Spring and systemd

Schedulers outside crontab write the same schedule differently: Jenkins picks the minute and hour offset for you, Quartz and Spring add a seconds field, and systemd uses calendar events.

SchedulerEvery 2 hoursNotes
JenkinsH H/2 * * *Every 2 hours at a minute fixed per job, on the even or the odd hours depending on the job's name, so jobs don't all start at once. 0 */2 * * * also works
Quartz0 0 0/2 * * ?Seconds come first, and one day field must be ?. 0 0 */2 * * * fails with “Support for specifying both a day-of-week AND a day-of-month parameter is not implemented”. 0 0 1/2 * * ? gives the odd hours
Spring @Scheduled0 0 */2 * * *Six fields with seconds first; ? is optional. fixedRate = 2 with timeUnit = HOURS counts from startup instead of the clock
systemd timerOnCalendar=0/2:00Normalizes to *-*-* 00/2:00:00, the even hours. Check it with systemd-analyze calendar '0/2:00'
job.timer
# /etc/systemd/system/job.timer (with a matching job.service)
[Timer]
OnCalendar=0/2:00
Persistent=true

[Install]
WantedBy=timers.target

Persistent=true runs a missed job once when the machine is back on, which cron never does. To run 2 hours after the last run started instead of on the clock, use a monotonic timer:

job.timer
[Timer]
OnBootSec=10min
OnUnitActiveSec=2h

OnBootSec starts the first run 10 minutes after boot, and OnUnitActiveSec=2h repeats it every 2 hours after that, so the times drift with boots rather than landing on even hours. The Quartz, Spring and systemd forms were checked with Quartz 2.5.1, Spring 6.2 and systemd-analyze.