Cron Expression Syntax in 60 Seconds
A cron expression is 5 space-separated fields that describe a schedule. Read them left to right:
┌───── 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, 0=Sunday)
│ │ │ │ │
* * * * * The Operators You Actually Use
*— every value (every minute, every hour, etc.)*/N— every N units (*/5 * * * *= every 5 minutes)A,B,C— list (0 9,12,17 * * *= 9am, noon, 5pm)A-B— range (0 9 * * 1-5= weekdays at 9am)A-B/N— range with step (0 9-17/2 * * *= every 2 hours from 9 to 17)
Common Schedules
*/5 * * * *— every 5 minutes0 * * * *— every hour, on the hour0 9 * * 1-5— every weekday at 9am0 0 1 * *— first of every month at midnight0 0 * * 0— every Sunday at midnight (weekly)
Common Pitfalls
- Day of week 0 vs 7 — both mean Sunday in most cron implementations, but some use 1-7 (Monday=1). Check your runtime.
- Timezone — most cron daemons run in the server's local time. Set
TZexplicitly or use UTC to avoid surprises. - Day-of-month AND day-of-week — when both are specified, standard cron uses OR (matches either), Quartz uses AND. Be careful with libraries.
- Overlapping runs — if your job takes longer than the interval, you'll get concurrent runs. Use a lockfile or distributed lock.