Run a cron job on the last day of every month
crontab has no exact expression for “Last day of the month”. Here is why, a workaround, and the platforms that can do it. crontab is the classic Unix scheduler: five time fields and a command, in the server’s time zone.
Why crontab can’t do this exactly
Defined on Quartz as 0 0 0 L * ? · “At 00:00, on the last day of the month”
day of month: crontab has no “last day of the month”. Months end on the 28th to the 31st, so no single day matches.
WorkaroundRun on days 28-31 and exit unless tomorrow is the 1st. Needs GNU date; in crontab, % is escaped as \%.
Not equivalent on its own: it needs a check inside the job.0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /path/to/job
crontab gotchas
FAQ
What is the crontab cron expression for “Last day of the month”?
There is none that matches exactly. crontab has no “last day of the month”. Months end on the 28th to the 31st, so no single day matches.
Which time zone does a crontab schedule use?
In the server’s local time zone. cronie reads a CRON_TZ= line for the entries below it; check which cron your system runs before you rely on it.
How do I edit my crontab?
Run crontab -e to edit and crontab -l to list. Each line is five time fields followed by the command.
Is Sunday 0 or 7 in crontab?
Both. crontab accepts 0 and 7 for Sunday, and names such as SUN.