Behind every automated nightly database backup, morning newsletter dispatch, and stale cache purge sits a 50-year-old Unix daemon called cron. Yet despite its simplicity, poorly crafted cron strings routinely trigger runaway job loops, missed batch billing cycles, and catastrophic midnight server spikes.
1. The Five Magic Asterisks: How Vixie Cron Still Runs the Internet
Standard Unix Vixie Cron uses five whitespace-separated positional fields. Every minute, the daemon evaluates system crontabs against the current system wall clock:
┌───────────── Minute (0 - 59)
│ ┌─────────── Hour (0 - 23)
│ │ ┌───────── Day of Month (1 - 31)
│ │ │ ┌─────── Month (1 - 12)
│ │ │ │ ┌───── Day of Week (0 - 6, where 0 = Sunday)
│ │ │ │ │
* * * * *
2. Field-by-Field Breakdown
| Field Name | Allowed Range | Common Pitfall |
|---|---|---|
| Minute | 0 – 59 | Leaving as * when intending once an hour triggers the job every single minute! |
| Hour | 0 – 23 | 24-hour military notation (0 = Midnight, 12 = Noon, 23 = 11 PM). |
| Day of Month | 1 – 31 | Setting 31 skips February, April, June, September, and November completely! |
| Month | 1 – 12 | 1 = January, 12 = December. |
| Day of Week | 0 – 6 (or 7) | In Unix standard, 0 and 7 both represent Sunday. 1 is Monday. |
3. The Daylight Saving Time (DST) & Midnight Overlap Pitfalls
Two subtle bugs account for over 80% of cron-related production outages:
- The DST Time Shift: Jobs scheduled between 2:00 AM and 3:00 AM in locales with Daylight Saving Time may execute twice in autumn (when clocks roll back) or be skipped completely in spring (when clocks spring forward). Best practice: Always configure production servers and cron schedulers in UTC.
- The Day-of-Month vs Day-of-Week OR Trap: If both Day-of-Month and Day-of-Week are specified as non-asterisks (e.g.
0 2 15 * 5), Unix cron uses OR logic, not AND logic! The job runs on the 15th of the month AND on every Friday.
4. Mastering Wildcards: Asterisks, Commas, Hyphens, and Slashes
Special characters unlock granular schedules without duplicate lines:
*(Wildcard): Match every possible value in this field.,(List): Match specific intervals, e.g.0 9,12,15 * * *runs at 9 AM, 12 PM, and 3 PM.-(Range): Match inclusive spans, e.g.0 9 * * 1-5runs Monday through Friday./(Step): Match increments, e.g.*/15 * * * *runs every 15 minutes.
5. How to Validate & Generate Cron Expressions Without Broken Production Jobs
Before committing a scheduled task to your Kubernetes Helm chart, GitHub Actions workflow, or Linux /etc/crontab:
- Translate the raw expression into plain English (e.g. "At 03:00 on day 1 of every month").
- Inspect the next 5 simulated execution timestamps to verify interval consistency.
- Avoid scheduling heavy database reports exactly at midnight (
00:00); offset by a few minutes (e.g.00:17) to avoid concurrent server contention.
Written by Qwertygen Team
Engineering & Editorial Team at Qwertygen. Passionate about client-side document processing, data privacy invariants, and high-performance browser tooling.