Standard cron has no way to say “the last day of the month”. The day-of-month field takes numbers 1 to 31, lists, ranges and steps, but the last day is 28, 29, 30 or 31, depending on the month. The characters L and W that appear in some guides belong to Quartz-style schedulers, not to the cron that runs on Linux servers.
Why the obvious tries fail
0 0 31 * *runs only in months with 31 days: the parser lists 31 October, 31 December, 31 January, 31 March and so on, and skips the months in between.0 0 30 * *skips February;0 0 29 * *skips February in common years.0 0 28-31 * *runs on every day from the 28th to the 31st that exists, as the parser shows for October: 28, 29, 30 and 31. That is the right start, but too many runs.
Solution 1: run on days 28-31 and test whether tomorrow is the 1st
Let cron run on each candidate day, and let the shell decide whether it is really the last one:
0 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /usr/local/bin/month-end.sh
If tomorrow’s day number is 01, today is the last day, and the job runs. The \% is needed because an unescaped % ends a crontab command. This is the most common answer. On macOS or BSD, replace the date part with date -v+1d +\%d. Put it in a script if you want to avoid the escaping and the &&.
Solution 2: run on the 1st and process the previous month
Often the job does not need to run on the last day; it needs the whole month to be finished. Run it in the first minutes of the next month:
10 0 1 * * /usr/local/bin/month-end.sh --month "$(date -d 'yesterday' +\%Y-\%m)"
It uses a plain schedule (see first day of the month), skips the guesswork, and passes the month explicitly, so a late or repeated run does the same work. Reports that include the last day’s data should wait until a few minutes after midnight, anyway.
Solution 3: a different scheduler
systemd timers have a calendar syntax that knows about month ends: OnCalendar=*-*~01 counts one day back from the end of each month, which is the last day. OnCalendar=*-*~01 23:30:00 runs at 23:30 on the last day. Schedulers such as Quartz accept 0 0 L * ?. If you are free to choose, a systemd timer is the cleaner fit on a Linux server.
Check your work
Paste the expression into the cron parser, which describes the 28-31 form as “At 00:00, on day 28 through 31 of the month”, and read the list of runs for the next few months; for the 28-31 form you must see 28, 29, 30 and 31 in a 31-day month, and the shell test is what narrows it down. The test itself is not part of the cron expression, so try it on the shell with the dates around a month end: date -d '2026-02-28 +1 day' +%d prints 01, and date -d '2026-03-30 +1 day' +%d prints 31.
Time zone
The “last day” is in the time zone of the system. A server in UTC reaches the end of the month seven hours before Vietnam (UTC+7) does, so a job at 23:00 UTC on the last day runs at 06:00 on the 1st in Hanoi. Be careful with what “the end of the month” means for the data you process; cron and time zones goes into that. The cron builder helps with the schedule part.
Frequently asked questions
Is there an L for 'last day' in cron?
Not in standard Unix cron. L exists in Quartz and in some schedulers (Spring, AWS EventBridge), but Vixie cron, cronie and busybox do not understand it, and the line is rejected or misread.
Why not just use 0 0 31 * *?
It runs only in months that have 31 days: seven months a year. The other five are skipped. Using 30 or 29 has the same problem in shorter months.
What is the simplest reliable way?
Run the job on the 1st of the next month and have it process the previous month. It is a single clean cron line, and there is no test of the calendar in it.
Does the date test work on macOS?
The GNU form date -d tomorrow does not. On macOS and BSD write date -v+1d +%d. Pick one that matches your system, or use a small script that does the check in a language you know.
More in this reference
- Cron daily at midnight (0 0 * * *): @daily, time zones and a better hour
- Cron every 5 minutes (*/5 * * * *): syntax, the step operator and its limits
- Cron every 6 hours (0 */6 * * *): steps in the hour field
- Cron every 15 minutes (*/15 * * * *): quarter hours and staggered starts
- Cron every hour (0 * * * *): @hourly, and the mistake of * 0 * * *
- Cron every minute (* * * * *): how it works and the traps
- Cron every Monday at 9 AM (0 9 * * 1) and the day-of-month OR trap
- Cron on the first day of the month (0 0 1 * *): @monthly and its limits
- Cron on weekdays at 9 AM (0 9 * * 1-5): Monday to Friday