Run Recurring Jobs Every Four Hours | CronBase

cron expression Standard
$ 0 */4 * * *

Every four hours at the top of the hour.

The `0 */4 * * *` cron expression schedules a task to execute every four hours at the top of the hour. Specifically, the job runs at midnight, 4:00 AM, 8:00 AM, 12:00 PM, 4:00 PM, and 8:00 PM daily, making it ideal for semi-frequent maintenance tasks and system synchronization.

Minute
0
Hour
*/4
Day of Month
*
Month
*
Day of Week
*
How it works

Next 5 Runs

  • in 3h 23m
  • in 7h 23m
  • in 11h 23m
  • in 15h 23m
  • in 19h 23m

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash
# Production Bash script for 4-hour cron execution
set -euo pipefail
LOG_FILE="/var/log/my_app_four_hour_job.log"
exec >> "$LOG_FILE" 2>&1
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Starting 4-hour maintenance task..."
LOCK_FILE="/var/run/my_app_four_hour_job.lock"
exec 200>"$LOCK_FILE"
if ! flock -n 200; then
    echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] ERROR: Another instance is already running." >&2
    exit 1
fi
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Running database maintenance..."
# Workload logic goes here
echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] Task completed successfully."
Setup notes

Save this script to /usr/local/bin/four-hour-job.sh, make it executable with 'chmod +x', and add the entry '0 */4 * * * /usr/local/bin/four-hour-job.sh' to your crontab.

Last verified:

Partner UptimeRobot

Keep this cron job monitored 24/7

UptimeRobot alerts you the moment a scheduled job stops responding. Free plan monitors up to 50 endpoints — no credit card required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 */4 * * ? *)

Systemd Timer

OnCalendar*-*-* 00/4:00:00

my-task.timer
[Unit]
Description=Timer for cron expression: 0 */4 * * *

[Timer]
OnCalendar=*-*-* 00/4:00:00
Persistent=true

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

At what exact times of the day does this cron schedule execute?

The schedule executes exactly six times a day at the top of the hour: 00:00, 04:00, 08:00, 12:00, 16:00, and 20:00. This is based on the system timezone unless specified otherwise.

How does Daylight Saving Time affect this 4-hour schedule?

If your system runs on local time, DST shifts can cause the 02:00 to 03:00 transition to skip or repeat an execution. To avoid this, configure your servers to use UTC timezone.

What happens if a job takes longer than 4 hours to complete?

Standard cron will launch a new process even if the previous one is still running. You must use locking mechanisms like flock (Bash) or Redlock (Redis) to prevent overlapping executions.

How can I add a 15-minute offset to this schedule?

You can modify the minute field from 0 to 15, resulting in '15 */4 * * *'. This helps avoid resource spikes at the exact top of the hour.

Is this schedule supported out-of-the-box in AWS EventBridge?

AWS EventBridge uses a different cron syntax (6 fields). To achieve this schedule in AWS, you would use 'cron(0 */4 * * ? *)' or a rate expression like 'rate(4 hours)'.

* Explore

Related expressions you might need

Last verified:

Was this helpful?