Cron job every 2 hours: expression and example
The cron expression for every 2 hours, on the hour is 0 */2 * * *. Put it at the start of a crontab line, followed by the command. Below: what each of the five fields does, a sample line you can copy, the mistakes people make with this schedule, and how to get told when the job doesn't run.
The expression
A cron expression has five fields separated by spaces: minute, hour, day of month, month, day of week. An asterisk means "every"; a number means "only this one"; */n means "every nth"; a-b is a range and a,b is a list. For every 2 hours, on the hour the fields are:
| Field | Value | Meaning |
|---|---|---|
| Minute (0-59) | 0 | minute 0 |
| Hour (0-23) | */2 | every 2nd hour: 0, 2, 4 ... 22 |
| Day of month (1-31) | * | every day |
| Month (1-12) | * | every month |
| Day of week (0-7, Sunday is 0 or 7) | * | every day of the week |
Example crontab line
Open the crontab with crontab -e and add one line: the expression, a space, then the command exactly as you'd type it in a shell. Longer data syncs, generating sitemaps for a big site, re-checking external prices. A typical line looks like this:
0 */2 * * * /srv/app/bin/rebuild-sitemap >> /var/log/sitemap.log 2>&1
The >> file 2>&1 at the end sends both normal output and errors to a log file. Without it, cron tries to email the output to the user, which usually means it's lost.
Gotchas
0 */2 * * *runs on even hours (00:00, 02:00 ...). For odd hours use0 1-23/2 * * *.- Each run is two hours apart only in the server's timezone. During a daylight-saving shift one gap becomes one or three hours.
- Timezone: cron uses the server's system timezone, which on most cloud servers is UTC. Run
dateon the server to see what "now" means to cron. - Environment: cron runs with a minimal PATH and no shell profile. Use full paths (
/usr/bin/python3, notpython3) and set any variables at the top of the crontab. - Output: if a job prints anything and there's no redirect or MAILTO, cron tries to send mail. Set
[email protected]at the top of the crontab or redirect output to a log. - Silence: cron does not tell you when a job fails or never starts. A job that errors every run looks exactly like a job that runs fine, unless something is watching for it.
Know when it didn't run
In short: Append && curl -fsS https://heyuptime.com/ping/<token> to the line, create a heartbeat monitor with a 6 hours period and 30 minutes grace, and you're alerted when the job is late.
A heartbeat monitor in heyUptime is a URL your job calls when it finishes. Because of the &&, the ping is only sent when the command exits successfully, so a crashing job and a job that never started look the same: no ping. The watched line for this schedule is 0 */2 * * * /srv/app/bin/rebuild-sitemap && curl -fsS https://heyuptime.com/ping/<token>.
Set the heartbeat's period to 6 hours and the grace to 30 minutes. If a ping doesn't arrive within period plus grace, you get an alert by email, Slack, Discord, Teams or Telegram that says when the job was last seen. heyUptime's heartbeat periods jump from 1 hour to 6 hours, so for a 2-hour job pick 6 hours: you're alerted after three missed runs. If one missed run matters, choose 1 hour and have the job also ping on the odd hours with a lightweight curl line.
To try it before signing up, the free cron job tester gives you a temporary URL for 24 hours; add it to the line and watch the ping arrive.
Questions
What is the cron expression for every 2 hours?
0 */2 * * *: at minute 0 of every even hour, 12 times a day.
How do I run every 2 hours starting at 1am?
0 1-23/2 * * *. The range 1-23 with step 2 gives 1, 3, 5 ... 23.
How do I monitor a 2-hour job?
Add a heartbeat ping to the crontab line and pick the 6-hour period with a 30-minute grace; that alerts after three missed runs. For a tighter check, use the 1-hour period and ping from a second, lighter crontab line on the odd hours.
Watch this job for free.
Create a heartbeat with a 6 hours period, add one curl to the crontab line, and get told the first time it doesn't run. 14-day trial, no card.
Related
- Cron job monitoring
- Cron job tester
- Cron job every hour
- Cron job every 6 hours
- Cron job every minute: expression and example
- Cron job every 5 minutes: expression and example
- Cron job every 10 minutes: expression and example
- Cron job every 15 minutes: expression and example
- Cron job every 30 minutes: expression and example
- Cron job every hour: expression and example
Updated October 8, 2026.