Cron on the first day of the month (0 0 1 * *): @monthly and its limits

Open this example in the tool

Try it in the tool

Cron Expression Parser

Read cron schedules in plain English and see when they run next.

Cron Expression Generator

Pick a schedule, get the cron expression and its next run times.

0 0 1 * * runs at 00:00 on the first day of every month. The cron parser says “At 00:00, on day 1 of the month” and the next runs fall on 1 November, 1 December, 1 January and so on — a few weeks apart, but always on the 1st. @monthly is the same schedule.

0 0 1 * * /usr/local/bin/monthly-invoices.sh >> /var/log/invoices.log 2>&1

Why day 1 is the safe day

Every month has a day 1, so the job never skips a month. Day 29, 30 and 31 do not exist in every month: 0 0 31 * * runs only in months with 31 days (the parser lists 31 October, 31 December, 31 January, 31 March, 31 May and so on), so no run in February, April, June, September or November. If the job must run “at the end of the month”, read last day of the month for the usual workarounds.

Variants

Goal Expression
1st at 02:30 30 2 1 * *
1st and 15th 0 0 1,15 * *
1st of every quarter (January, April, July, October) 0 0 1 1,4,7,10 *
1st of January only 0 0 1 1 * (@yearly or @annually)
Every 3 months 0 0 1 */3 * (months 1, 4, 7, 10)

The step in the month field counts from January, so */3 gives 1, 4, 7 and 10. */2 gives the odd months (1, 3, 5, … 11), not “every second month from today”.

First Monday, first weekday

Do not try 0 9 1-7 * 1 for the first Monday. When both the day-of-month and the day-of-week fields are restricted, cron runs the job if either matches, so this fires on days 1 to 7 and on every Monday. Use one of the safe forms from every Monday at 9: run every Monday and add a check of the day number in the command.

For the first working day, run on days 1 to 3 and test in the script that today is a weekday, and that yesterday (or the days before) in the same month was not a working day. A holiday list also lives in the script.

Practical advice

  • Run it a little after midnight, or at night, so that the previous month’s data is complete: 15 3 1 * * is calmer than 0 0 1 * *, which collides with every other monthly job and with the date change.
  • Process by date, not by “now”. Calculate the month to report on from the date and pass it as an argument, so that a delayed or repeated run produces the same result.
  • Keep the time zone in mind. On a UTC server the 1st starts seven hours earlier than in Vietnam (UTC+7), so the job at 0 0 1 * * runs at 07:00 local time on the 1st. See cron and time zones.
  • Monitor it. A job that runs once a month is easy to forget until the quarter closes. A heartbeat check that expects a ping within 32 days catches a silent failure.

The cron builder builds monthly expressions by choice. For daily jobs, see daily at midnight.

Frequently asked questions

What is the cron expression for the first day of every month?

0 0 1 * *: 00:00 on day 1 of every month. @monthly is a shortcut for it on most systems.

Why did my job skip some months when I used day 31?

Months with fewer than 31 days have no day 31, so the job does not run in them. Day 29 and 30 have the same problem in February. Day 1 exists in every month, which is why monthly jobs normally use it.

Can cron run on the first Monday of the month?

Not with the fields alone, because day-of-month and day-of-week are joined by OR. Run every Monday and test the date in the command, as shown on the every-Monday page.

How do I run on the first working day?

Run on days 1 to 3 on weekdays and let the script check that this is the first working day, or run daily and test. A holiday list belongs in the script, since cron has no calendar.

More in this reference