Cron expression for the last day of the month
Runs the job at midnight on the last day of every month, whatever that day is.
0 0 L * *
At 12:00 AM, on the last day of the month
Field by field
- Minute · 0–59
0only at minute 0 - Hour · 0–23
0only at 00:00 - Day of month · 1–31
Lthe last day of the month - Month · 1–12 or JAN–DEC
*every month - Day of week · 0–7 or SUN–SAT
*every day of the week
Next runs in your local time
Why this schedule, and when it bites
Month-end jobs share one awkward property: the date moves. Rent runs, invoice closing, usage rollups and archive rotations all want the last day, not the 31st. Schedulers in the Quartz family solve it with L in the day-of-month field: 0 0 L * * fires at midnight on the 28th of February and on the 31st of January, with no conditional logic in the script.
L is not in the crontab on your Linux box. The L token comes from Quartz-style schedulers and from libraries such as cron-parser. The Vixie cron that ships with Debian, Ubuntu and RHEL has no L and rejects or skips the line. On a plain server, run 0 0 28-31 * * and let the script exit unless tomorrow is the 1st.
28-31 alone is not the last day. Written bare, the range fires on the 28th, 29th and 30th as well: three runs in a 31-day month, two in February. The guard belongs at the top of the job: test "$(date -d tomorrow +%d)" = "01" or exit. Without it, month-end reports run early and the numbers are wrong.
Midnight belongs to the next month. 0 0 L * * starts the job at 00:00 on the last day, which is usually what closing wants. But a job that sums today so far at midnight sums an empty day. If the report must cover the finished month, run it late on the last day or make the script pick the month it reports on explicitly.
Where this cron expression shows up
- Month-end closing: invoices and reports that have to land in the month being closed
- Archiving or clearing data before the calendar flips to a new month
- A final metrics rollup for the month that just ended
Common variations
-
The same day, at 23:00 instead of midnight
0 23 L * * At 11:00 PM, on the last day of the month
-
For schedulers without L (classic crontab): fires on the 28th, 29th and 30th too, so the job itself must check that tomorrow is the 1st
0 0 28-31 * * At 12:00 AM, between day 28 and 31 of the month
-
The first day of the month instead
0 0 1 * * At 12:00 AM, on day 1 of the month
L is the last day of the month. Quartz and cron-parser understand it; the Vixie cron that ships with most Linux systems does not, so a crontab entry needs the guarded 28-31 version above. Writing 28-31 on its own is the trap: it fires on three days in a 31-day month and on two in February.
Ranges, steps, and names are spelled out on the cheat sheet.
Questions this schedule raises
Why does 0 0 L * * work in some tools and not in crontab?
L is an extension from Quartz-class schedulers, adopted by many libraries, cron-parser among them. Linux Vixie cron treats expressions as five plain fields and has no L. The parser on this site accepts L and shows the firing days, but a crontab line needs the 28-31 workaround with an in-script date check.
What is the shortest correct crontab for the last day of the month?
0 0 28-31 * * plus a guard as the first line of the job that exits unless tomorrow is the 1st. It fires at most once per month, on the last day, and costs one line. With systemd, a monthly timer on the 1st is the common alternative: the job runs next morning and reports on the month that just ended.