The POSIX Cron Day-of-Month + Day-of-Week OR Trap (0 9 13 * 5 Runs Every Friday)
Why specifying both Day-of-Month and Day-of-Week in POSIX crontab evaluates as boolean OR (union) instead of AND, and how to guard intersection schedules.
Incident Symptom & Protocol Root Cause
Production Failure Symptom
An engineer writes 0 9 13 * 5 expecting a job to run only on 'Friday the 13th' (or 0 9 1-7 * 1 expecting 'the first Monday of the month'), but in production the job fires every single Friday of the year PLUS the 13th of every month (or every day from the 1st through the 7th PLUS every Monday).
Scheduler Parser & Clock Mechanics
Per POSIX.1-2017 crontab specification, when neither Day-of-Month (field 3) nor Day-of-Week (field 5) is a single asterisk (*), the cron daemon matches dates satisfying EITHER field (boolean OR union), whereas minute, hour, and month combine via boolean AND.
Broken vs Verified Configuration
# Intended: First Monday of every month at 09:00 UTC
# Actual behavior: Runs Dec 1,2,3,4,5,6,7 AND Dec 8,15,22,29 (10+ times/month!)
0 9 1-7 * 1 /opt/scripts/monthly-invoice-run.sh
# Intended: Only Friday the 13th at 09:00 UTC
# Actual behavior: Runs every Friday AND the 13th of every month!
0 9 13 * 5 /opt/scripts/audit-check.sh# Fix 1: Keep '*' in Day-of-Week and guard weekday in shell (note % in crontab!)
0 9 1-7 * * [ "$(date +%u)" = "1" ] && /opt/scripts/monthly-invoice-run.sh
# Fix 2: Keep '*' in Day-of-Month and guard date == 13 in shell
0 9 * * 5 [ "$(date +%d)" = "13" ] && /opt/scripts/audit-check.sh
# In GitHub Actions / Kubernetes YAML (no crontab % escaping needed):
# command: ["/bin/sh", "-c", "[ "$(date +%u)" = "1" ] && /opt/scripts/monthly-invoice-run.sh"]Operational Deep Dive
The DOM/DOW union rule is one of the oldest and costliest traps in Unix administration. POSIX.1-2017 states explicitly: if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the month and day of week, shall be matched. GitHub Actions on.schedule and Kubernetes CronJob inherit this exact POSIX union rule.
Subtle parser quirks make naive workarounds even more dangerous. In Paul Vixie's cron implementation, the OR check literally tests whether the first character of the DOM or DOW string is '*' — meaning an obfuscated wildcard such as */1 or 1-31 in field 3 causes Vixie Cron to treat field 3 as restricted, turning 0 9 */1 * 1 into 'every single day OR Monday' (running 7 days a week!).
Cross-platform migrations fail in the opposite direction as well: systemd OnCalendar expressions such as Fri *-*-13 09:00:00 evaluate weekday and calendar day using boolean AND (intersection), while AWS EventBridge rejects expressions where both fields are specified without a ? wildcard (ValidationException). Whenever you need true intersection in POSIX cron, leave one of field 3 or field 5 as a literal * and enforce the second condition with date +%u or date +%d.
Day-of-Month + Day-of-Week Boolean Logic Across Platforms
| Engine / Case | Runtime Behavior | Production Remediation |
|---|---|---|
| POSIX / Vixie Cron / Cronie | Boolean OR (union) whenever both field 3 (DOM) and field 5 (DOW) are non-'*'. | Set one field to literal '*' and add [ "$(date +\%u)" = "..." ] && guard before command. |
| GitHub Actions & Kubernetes CronJob | Inherits POSIX boolean OR union; 0 9 1-7 * 1 runs 10–11 times per month. | Use schedule: '0 9 1-7 * *' and check date +%u in step if: or container shell entrypoint. |
| AWS EventBridge (Rules & Scheduler) | Hard syntax error unless either DOM or DOW is '?' (supports native 2#1 Nth-weekday instead). | Use cron(0 9 ? * 2#1 *) for first Monday, or create two separate schedules if union was intended. |
| systemd.timer (OnCalendar=) | Boolean AND (intersection): Mon *-*-01..07 09:00:00 natively matches ONLY the first Monday. | When migrating systemd timers back to crontab, NEVER copy DOM+DOW directly without a shell guard. |
Edge Cases & Engineering FAQs
Why did my crontab guard [ "$(date +%u)" = "1" ] fail with an unexpected EOF error?
In standard Vixie /etc/crontab and user crontabs, unescaped percent signs (%) are converted into newline characters by the cron daemon before passing the command to /bin/sh, truncating the command at +%u. Always escape percent signs as \% inside crontab files (do NOT escape % inside Kubernetes YAML or GitHub Actions run: blocks).
Does date +%u use 0 or 7 for Sunday?
ISO 8601 date +%u always maps Monday=1 through Sunday=7 across GNU coreutils, BSD/macOS, and BusyBox. By contrast, date +%w maps Sunday=0 through Saturday=6. Prefer +%u so Monday is unambiguously 1.
Which field should keep '*' when guarding Nth weekday of the month?
Leave Day-of-Week as '*' (0 9 1-7 * *) so cron wakes up only 7 mornings per month instead of waking up every Monday (4–5 mornings) or vice versa—waking on the 4–5 target weekdays (0 9 * * 1) with a [ "$(date +\%d)" -le 7 ] check actually runs slightly fewer shell evaluations (4.3 vs 7 per month).
Runtime Dead-Man's-Switch Verification
Dead-man's-switch heartbeat checks that page on-call when a scheduled job skips a DST gap, stalls on a lock, or exits non-zero.