Reliable HTTP cron and delayed-job scheduling with automatic retries and full run logs — delay.run

Here's a cron line that looks like it means "9 a.m. on Monday the 1st":

0 9 1 * 1 /usr/local/bin/monthly-report 

It doesn't. It runs at 9 a.m. on the 1st of every month, and at 9 a.m. every Monday. That's about five runs a month instead of one or two a year. Nobody finds out until the report has gone to customers four times.

This is one of the oldest surprises in cron, and it's documented right there in man 5 crontab. Here's the rule, the quirk inside the rule, and recipes for the schedules people usually meant.

The rule

A cron expression has five fields: minute, hour, day of month, month, day of week. Minute, hour and month are combined with AND, as you'd expect. The two day fields are special:

  • If only one of day-of-month and day-of-week is restricted (the other is *), the restricted one applies. 0 9 1 * * is the 1st of the month. 0 9 * * 1 is every Monday.
  • If both are restricted, the job runs when either matches. 0 9 1 * 1 is the 1st of the month OR any Monday.

From the Vixie cron man page, which most Linux distributions inherit: "If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time."

The same behaviour shows up in most cron-compatible schedulers that copy the classic semantics, including the library behind Kubernetes CronJobs and many hosted schedulers. Some don't (more on that below), which is another reason to check rather than assume.

The quirk: what counts as "restricted"

In Vixie cron and its descendants, a field counts as unrestricted if it starts with *. That includes step values like */2.

So:

0 9 */2 * 1 # every other day... OR every Monday? Actually: AND. 

Because */2 begins with *, cron treats the day-of-month field as unrestricted and switches to AND logic: this runs on odd-numbered days of the month that are also Mondays. Write the same days as 1-31/2 and it switches back to OR: every odd-numbered day, plus every Monday.

Same days, same intent, different behaviour depending on spelling. If you need to rely on it, test it with the actual implementation you're running.

If cron's day-of-month / day-of-week rule still surprises you, delay.run uses an explicit schedule and logs every run, so a job can't quietly fire on both the 1st and every Monday.

Recipes for what people usually meant

Since standard cron can't express "Monday AND the 1st" directly, the usual trick is to let cron handle one condition and a small shell test handle the other.

One gotcha first: in a crontab, % is special (it means newline), so every % in a date format must be escaped as \%.

The first Monday of the month

The first Monday always falls on days 1 to 7. Let cron pick Mondays and check the date in the command:

0 9 * * 1 [ "$(date +\%d)" -le 07 ] && /usr/local/bin/monthly-report 

Or the other way round: let cron pick days 1 to 7 and check the weekday (%u is 1 for Monday):

0 9 1-7 * * [ "$(date +\%u)" -eq 1 ] && /usr/local/bin/monthly-report 

The first version wakes up four or five times a month, the second seven times. Both run the real job once.

The second Tuesday (Patch Tuesday style)

Days 8 to 14:

0 9 8-14 * * [ "$(date +\%u)" -eq 2 ] && /usr/local/bin/patch-tuesday 

The last Friday of the month

The last Friday is the Friday where adding seven days lands in the next month. With GNU date:

0 17 * * 5 [ "$(date -d '+7 days' +\%m)" != "$(date +\%m)" ] && /usr/local/bin/end-of-month 

On macOS or BSD, date -v+7d +\%m does the same.

The last day of the month

Cron has no "last day" value in its standard form. Check whether tomorrow is the 1st:

0 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /usr/local/bin/close-books 

Better options if your scheduler has them

systemd timers

systemd's OnCalendar combines weekday and date with AND, which is what most people expect:

# first Monday of every month at 09:00 OnCalendar=Mon *-*-01..07 09:00:00 

Check any expression before you trust it:

systemd-analyze calendar --iterations=5 'Mon *-*-01..07 09:00:00' 

It prints the next five run times, which is the fastest way to catch a misunderstanding.

Quartz-style schedulers

Java's Quartz, and schedulers that adopt its syntax, support # for "nth weekday" and L for "last":

0 0 9 ? * MON#1 # first Monday, 09:00 0 0 17 ? * 6L # last Friday, 17:00 (Quartz numbers Sunday as 1) 

The ? means "no specific value" and avoids the OR problem entirely. Quartz has six or seven fields (seconds first), so these lines won't work in a regular crontab.

Always print the next runs

Whatever you use, don't deploy a schedule without seeing when it will actually fire. For classic cron expressions, a quick check in Python with the croniter package:

from croniter import croniter from datetime import datetime it = croniter("0 9 1 * 1", datetime(2026, 11, 14)) for _ in range(6): print(it.get_next(datetime).strftime("%a %Y-%m-%d %H:%M")) 

If the output includes more Mondays than you expected, you've just saved yourself a very awkward email to customers. Hosted schedulers often show upcoming run times when you create a schedule. Whatever you use, delay.run, a cloud scheduler or a plain crontab, read that list before you save.

Related reading

Have you been caught by the day-of-month OR day-of-week rule? And did you know about the */2 quirk before reading this? I didn't, for an embarrassingly long time.