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
*

Next 5 Runs

  • in 2h 3m
  • in 6h 3m
  • in 10h 3m
  • in 14h 3m
  • in 18h 3m

* Tools

Code & Implementations

nodejs
const cron = require('node-cron');
const { exec } = require('child_process');

// Schedule task to run every 4 hours (0 */4 * * *)
cron.schedule('0 */4 * * *', () => {
    console.log(`[${new Date().toISOString()}] Starting scheduled 4-hour job...`);
    try {
        performMaintenance().catch(err => {
            console.error('Task execution failed:', err);
        });
    } catch (error) {
        console.error('Failed to trigger task:', error);
    }
});

async function performMaintenance() {
    // Simulated production workload
    return new Promise((resolve) => setTimeout(resolve, 5000));
}
Setup notes

Install 'node-cron' using 'npm install node-cron' and run this script as a long-running background process using a process manager like PM2.

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

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

Was this helpful?

Last verified: