The Architecture of Cron: POSIX Crontab Syntax & Scheduling Mechanics
Originating in Version 7 Unix (1979) and standardized by POSIX, cron is a background time-based job scheduler. A crontab (cron table) file contains scheduled commands executed automatically at fixed times, dates, or recurring intervals.
1. The Standard 5-Field Syntax Layout
Standard Unix and Linux crontab expressions consist of five space-delimited fields:
┌───────────── Minute (0 - 59)
│ ┌───────────── Hour (0 - 23)
│ │ ┌───────────── Day of Month (1 - 31)
│ │ │ ┌───────────── Month (1 - 12 or JAN - DEC)
│ │ │ │ ┌───────────── Day of Week (0 - 6 or SUN - SAT, where 0 and 7 = Sunday)
│ │ │ │ │
* * * * *
2. Special Character Operators Explained
| Operator | Meaning | Example | Interpretation |
|---|---|---|---|
* (Asterisk) |
Any value (wildcard) | * * * * * |
Every minute of every day |
, (Comma) |
Value list separator | 15,45 * * * * |
At minute 15 and minute 45 |
- (Hyphen) |
Inclusive value range | 0 9-17 * * * |
Every hour from 09:00 to 17:00 |
/ (Slash) |
Step interval | */10 * * * * |
Every 10 minutes starting at 00 |
3. The Critical Day-of-Month vs Day-of-Week Pitfall
A notorious trap in POSIX cron scheduling occurs when both Day of Month (field 3) and Day of Week (field 5) are specified (i.e., neither is set to *):
0 0 1,15 * 5
Developers often assume this schedule runs on Friday the 1st and Friday the 15th. This is incorrect! The POSIX standard explicitly mandates an OR condition:
The command executes if the day of the month matches 1 OR 15, OR if the day of the week is Friday.
To schedule a job on "the first Friday of the month", standard cron cannot express this directly without a bash conditional guard inside the command:
0 0 1-7 * 5 [ $(date +\%u) -eq 5 ] && /path/to/script.sh
4. Timezones & Daylight Saving Time (DST) Hazards
- Local Clock Shifts: If your server clock runs in local time zones observing DST (e.g.,
America/New_YorkorEurope/London), jobs scheduled between 02:00 and 03:00 will run twice during the autumn fall-back transition and will be skipped completely during the spring forward transition. - Production Best Practice: Configure all production server daemons, database schedulers, and Kubernetes clusters strictly in UTC (Coordinated Universal Time) to guarantee linear, uninterrupted job intervals.
5. Frequently Asked Questions (FAQ)
- Does this tool support 6-field cron expressions?
- Standard POSIX/Unix crontab uses 5 fields. Some schedulers like Spring Boot or Quartz use a leading 6th field for seconds (
0 */5 * * * *). This explainer focuses on the universal 5-field crontab format supported across Linux, macOS, AWS EventBridge, and Kubernetes. - Is Sunday 0 or 7 in cron?
- Both. In the standard Vixie cron daemon, both
0and7represent Sunday. Monday is1, and Saturday is6. - Can I use macro shortcuts like @hourly or @daily?
- Yes. Common crontab implementations support predefined macros:
@hourly(0 * * * *),@daily/@midnight(0 0 * * *),@weekly(0 0 * * 0),@monthly(0 0 1 * *), and@yearly(0 0 1 1 *).