TechCompare LogoTechCompare

Run a cron job on the first of every month: 0 0 1 * * guide

0 0 1 * * is correct for first-of-month execution. For last-day-of-month scheduling, use a wrapper script or switch to systemd timers. If you need the 15th, 20th, or any day that exists in every month, the standard day-of-month field works without caveats.

0 0 1 * * runs a job at midnight on the first day of every month. The third field (1-31) controls the day of the month. This is the standard pattern for monthly billing runs, usage reports, and archival jobs that process the previous month's data.

By TechCompare · Updated

Schedule pattern
Monthly schedule
monthly
Category
Common Patterns
Standard cron expression patterns

How this is calculated

Not every month has 31 days. If you specify the 31st, the job simply won't run in February, April, June, September, or November. For the last day of the month, cron alone can't express it. The common workaround is to run on the 28th-31st and have the script check if tomorrow is the 1st. Alternatively, use 0 0 28-31 * * and let the script exit early if the date isn't the last day. Systemd timers handle this natively with OnCalendar=*-*-28..31 00:00:00 plus a script guard.

Verdict

First-of-month schedules are safe, but the day-of-month field hides a quiet trap: specifying the 31st silently skips February, April, June, September, and November. For last-day runs, standard cron can't express it, so the workaround is 28-31 with a script guard that checks if tomorrow is the 1st. systemd's OnCalendar=*-*-28..31 handles this natively without the script.

More Cron scenarios

Frequently asked questions

How do I run a cron job on the first of every month?
Use 0 0 1 * *. The third field is the day of month, and pinning it to 1 runs the job at midnight on the 1st of every month, every month. Monthly billing runs, usage reports, and archival jobs that process the previous month's data are the classic fits.
What happens if I schedule a cron job for the 31st of the month?
It silently skips months that don't have 31 days: February, April, June, September, and November. Cron doesn't warn you. The job simply never fires those months, which makes the 31st a trap for anything you expect to run reliably. Stick to days 1-28 for schedules that must run every month.
How do I run a cron job on the last day of the month?
Standard cron can't express it. The common workaround is 0 0 28-31 * * combined with a script that checks whether tomorrow is the 1st and exits early if it isn't. systemd timers handle this natively with OnCalendar=*-*-28..31 00:00:00 plus the same guard, which is the cleaner path on modern Linux.