Run Monthly System Tasks at Midnight | CronBase

cron expression Standard
$ 0 0 1 * *

At midnight on the first day of every month

The `0 0 1 * *` cron expression schedules a job to run exactly at midnight (00:00) on the first day of every calendar month. This highly predictable, low-frequency interval is commonly used in enterprise environments for processing monthly billing cycles, generating financial reports, archiving historical databases, and initiating full backup routines.

Minute
0
Hour
0
Day of Month
1
Month
*
Day of Week
*
How it works

Next 5 Runs

  • in 6d 3h
  • in 37d 3h
  • in 67d 3h
  • in 98d 3h
  • in 128d 3h

* Tools

Code & Implementations

Bash
#!/usr/bin/env bash

# Ensure the target script exists and is executable
CLEANUP_SCRIPT="/usr/local/bin/monthly_cleanup.sh"

if [ -f "$CLEANUP_SCRIPT" ]; then
  # Append the monthly cron job to the current user's crontab safely
  (crontab -l 2>/dev/null; echo "0 0 1 * * $CLEANUP_SCRIPT >> /var/log/monthly_cleanup.log 2>&1") | crontab -
  echo "Successfully scheduled monthly cleanup job."
else
  echo "Error: Target script $CLEANUP_SCRIPT not found. Cron job installation aborted." >&2
  exit 1
fi
Setup notes

Save this script as setup_cron.sh, make it executable with 'chmod +x setup_cron.sh', and run it. It registers the monthly cleanup script to execute at midnight on the 1st of every month, routing stdout and stderr to a dedicated log file.

Last verified:

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

OnCalendar*-*-01 00:00:00

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

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

[Install]
WantedBy=timers.target

Last verified:

Frequently Asked Questions

What happens if my server is offline at midnight on the first of the month?

Standard cron daemons will skip the execution entirely. To ensure the job runs when the system recovers, you should use anacron on Linux or configure a persistent queue/orchestrator (like Kubernetes with retry mechanisms or Airflow) that handles missed schedules.

How does Daylight Saving Time affect this monthly schedule?

If your server is set to a local timezone that observes DST, the midnight transition on the first of the month could occur twice (when falling back) or be skipped (when springing forward). To prevent this, always run cron jobs in UTC.

Can I run this job on the last day of the month instead of the first?

Standard cron does not easily support 'last day of the month' because months have varying lengths. You can either use a wrapper script that checks if tomorrow is the first, or use advanced dialects like Quartz or systemd timers that support the 'L' character (e.g., `0 0 L * *`).

How can I safely test a monthly cron job without waiting a full month?

You should separate your job execution logic from the scheduling mechanism. Write your script or application code to be triggerable via an HTTP endpoint, CLI command, or manual Kubernetes Job run, allowing you to test the execution on demand.

How do I handle overlapping executions if the monthly job takes over 24 hours?

To prevent overlapping runs, use lockfiles (like 'flock' in Bash), set 'concurrencyPolicy: Forbid' in Kubernetes, or implement a distributed lock pattern using Redis or database flags in your application code.

* Explore

Related expressions you might need

Last verified:

Was this helpful?