−50%

50% off your first month on any paid plan · code WELCOME50 · until Nov 30

Start free →
Guide

Cron Last Day of Month: Three Ways That Actually Work

There's no <code>L</code> flag in standard cron. Running a cron last day of month schedule has no dedicated field, no special character, nothing built in. But billing runs, month-end reports, and compliance exports all need to fire on that final day. Here are three approaches that work, ranked by how much you trust your shell skills.

Why cron last day of month doesn't work natively#

The day-of-month field accepts values 1-31 and step operators. That's it. Your crontab last day of month expression can't say "the last day, whatever number that happens to be." Months have 28, 29, 30, or 31 days, and cron has no way to look ahead and figure out which one applies.

Some extended cron implementations (Quartz, Spring, AWS EventBridge) support an L modifier in the day field. Standard crontab on Linux and macOS does not. If you're working with system crontab, you need a workaround.

We learned this the hard way running a monthly invoice generation script. Set it to day 31, it skipped February entirely, skipped April, skipped June, skipped September. A customer asked why their February statement never arrived, and by that point we'd missed four months of invoices across the year.

Approach 1: run on the 28th and call it close enough#

0 0 28 * *

Every month has a 28th. This is the simplest schedule and it's wrong by 0-3 days depending on the month. For internal reports that nobody checks until the 2nd of the next month anyway, does the exact day matter? Often it doesn't, and nobody will notice the difference.

The tradeoff is obvious enough to live with. January's "month-end" report covers 28 days instead of 31, while February's is spot-on. March is short by 3 days. If the report aggregates the full calendar month regardless of when it runs, this works fine. But if it captures "everything since the last run," you get uneven windows.

Approach 2: shell test for tomorrow being the 1st#

Run cron daily and let the command check whether tomorrow is the first of a new month:

0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /opt/scripts/month-end.sh

Breaking this down: this cron job last day of month pattern fires on the 28th through 31st (the only days that could be the last day). Cron silently skips days that don't exist in a given month, so the 28-31 range is safe even for February. The date -d tomorrow command checks if tomorrow's day is 01. If yes, today must be the last day of the month.

On February 28th in a non-leap year, tomorrow is March 1st so it fires, but in a leap year tomorrow is the 29th so it skips, and on the 29th itself tomorrow is March 1st so it fires then instead.

The \% escaping is required inside crontab because cron interprets bare % as a newline. Forget the backslash and the command silently breaks, no error, just no execution. We've debugged this exact issue three times for different teams, always the same fix.

On macOS, date -d doesn't exist. Use the BSD variant instead:

0 0 28-31 * * [ "$(date -v+1d +\%d)" = "01" ] && /opt/scripts/month-end.sh

This approach is reliable across all months and handles leap years correctly. The only cost is that cron runs the check command on 3-4 days per month where the condition is false, which is negligible.

Approach 3: use Cloud Cron with day-of-month = last#

Cloud Cron supports "last day of month" as a scheduling option without shell workarounds. Set your schedule, point it at your endpoint, and it fires on the correct day regardless of month length. No date arithmetic in bash, no escaped percent signs, no platform-specific date flags.

And this is the path of least resistance if your month-end task is an HTTP request, which most are at this point: trigger a webhook, call an API, hit a Laravel route that kicks off the job.

What about day 31 with a fallback?#

Sometimes you see this suggestion: schedule for day 31, and for months without a 31st, cron just doesn't fire. Then add a separate job for the 30th that checks if the month has 31 days.

Don't. It's fragile. Two crontab entries for one logical job, and the conditional logic gets messy around February. The "check if tomorrow is the 1st" approach handles every edge case in a single line.

Common use cases for cron last day of month#

Month-end cron jobs cluster around money and compliance. Invoice generation, billing cycle closures, financial report exports, usage summaries for SaaS customers, log rotation that aligns with monthly retention policies. So these are jobs where "close enough" creates audit findings and where missing a run means manual cleanup.

We see month-end jobs fail more often than weekly or daily ones. Not because the scripts are worse, but because a 30-day gap between runs means a 30-day gap before anyone notices the failure. A daily job that breaks gets caught tomorrow, but a monthly job that breaks in March might not surface until April.

Monitoring month-end cron jobs#

A job that runs once a month is the hardest to monitor manually. Miss it and you won't know for 30 days. Would you remember to check the log file on exactly the right day?

But you don't have to rely on memory or log files. Cron job monitoring removes the guesswork. Your script pings a URL on successful completion, WatchCron expects the ping on the last day of each month, and any missed ping triggers an alert through Slack, email, Telegram, or 16 other channels. For month-end jobs we recommend a grace period of 60 minutes, longer than usual because these jobs often process a full month of accumulated data and can run slower than expected.

For related scheduling patterns, see our guides on running cron every 3 days, on the first of each month, or the full cron jobs overview. You can also build and verify expressions before deploying.

Frequently asked#

There is no built-in cron last day of month expression. The most reliable workaround is 0 0 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /your/script.sh, which runs daily on the 28th-31st and checks if tomorrow is the 1st. If yes, today is the last day.

Only for months with 31 days. It skips February, April, June, September, and November entirely. That's 5 months per year with no execution, which makes it unreliable for month-end scheduling.

The "check if tomorrow is the 1st" approach handles leap years automatically. On Feb 28 in a leap year, tomorrow is the 29th (not March 1st), so the script correctly waits. On Feb 29, tomorrow is March 1st, so it fires.

Linux uses GNU date with -d tomorrow for relative date math. macOS uses BSD date with -v+1d for the same purpose. Using the wrong syntax for your OS causes silent failures because the date command errors out but cron suppresses the output.

Use cron job monitoring with a heartbeat ping. Your script pings a URL on completion, and WatchCron alerts you if the ping doesn't arrive by the expected date. Set a 60-minute grace period for month-end jobs that process large data volumes.

Written by Vitalii Holben

Founder of WatchCron. Full-stack developer building monitoring tools that help teams keep cron jobs, uptime, and SSL certificates under control. Based in Europe, shipping code since 2014.

Start monitoring in under 2 minutes.

Free plan includes 20 checks · No credit card required
Pricing Docs
Log in Start free →