Run Weekly Tasks Every Monday at Midnight | CronBase

cron expression Standard
$ 0 0 * * 1

Every single week at midnight on Monday morning

This standard cron expression schedules a task to execute every Monday at exactly midnight (00:00). It is widely used in production environments for weekly system maintenance, database indexing, log rotation, and generating business analytics reports before teams begin their workweek, ensuring clean system states and updated dashboards.

Minute
0
Hour
0
Day of Month
*
Month
*
Day of Week
1

Next 5 Runs

  • in 2d 14h
  • in 9d 14h
  • in 16d 14h
  • in 23d 14h
  • in 30d 14h

* Tools

Code & Implementations

nodejs
const cron = require('node-cron');
const { exec } = require('child_process');
// Schedule: 0 0 * * 1 (Every Monday at midnight)
cron.schedule('0 0 * * 1', async () => {
    console.log(`[${new Date().toISOString()}] Initiating weekly cleanup task...`);
    try {
        await runWeeklyTask();
        console.log(`[${new Date().toISOString()}] Weekly task finished successfully.`);
    } catch (error) {
        console.error(`[${new Date().toISOString()}] Critical failure during weekly task:`, error);
        // In production, integrate with PagerDuty, Sentry, or Slack webhook alert here
    }
});
function runWeeklyTask() {
    return new Promise((resolve, reject) => {
        // Mock database optimization or cleanup
        setTimeout(() => resolve(), 5000);
    });
}
Setup notes

Install node-cron via 'npm install node-cron'. Run this persistent Node process using a process manager like PM2 to guarantee continuous scheduling.

Partner BetterStack

Monitor this schedule in production

Get alerted the moment this cron job fails, is late, or doesn't run. BetterStack tracks execution, duration, and output — no infrastructure required.

Platform Equivalents

AWS EventBridge

Standard cron expressions often need conversion for AWS EventBridge schedules.

EventBridge Rule
cron(0 0 ? * 1 *)

Systemd Timer

OnCalendarMon *-*-* 00:00:00

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

[Timer]
OnCalendar=Mon *-*-* 00:00:00
Persistent=true

[Install]
WantedBy=timers.target

Frequently Asked Questions

How do I handle daylight saving time changes with this weekly schedule?

To prevent duplicate or skipped executions during daylight saving time (DST) shifts, configure your cron daemon or orchestrator to run in Coordinated Universal Time (UTC). If local time is required, use a modern scheduler like systemd-timer or Kubernetes CronJobs that natively handles DST transitions.

What happens if the server is offline at Monday midnight?

Standard cron daemons will skip the execution entirely if the server is offline at the scheduled time. If guaranteed execution is critical, use tools like `anacron` on Linux, or implement idempotent jobs with a queue-based scheduler that triggers missed runs upon system startup.

How can I prevent multiple weekly jobs from overloading the database at this time?

Implement a randomized startup delay or jitter (e.g., sleeping for a random duration between 1 and 10 minutes) at the beginning of your job execution. This distributes the database load and prevents resource contention from concurrent cron tasks.

Is it safe to use this schedule for log rotation?

Yes, this is a common pattern for weekly log rotation. However, ensure that logrotate or your custom script has a lock mechanism (such as `flock`) to prevent concurrent instances from running if a previous rotation hangs, and verify that services are gracefully reloaded to release file handles.

How does standard cron interpret the day-of-week field value of 1?

In the standard cron specification, the day-of-week field value of 1 represents Monday. Note that while 0 and 7 both represent Sunday in many modern implementations, 1 consistently and unambiguously represents Monday across all standard UNIX platforms.

* Explore

Related expressions you might need

Was this helpful?

Last verified: