Crontab is the standard job scheduler on Linux systems, but its five-field expression syntax can be cryptic. Understanding cron expressions is essential for every sysadmin β from simple daily backups to complex multi-condition schedules. This guide covers everything from basic syntax to advanced patterns, with a tool that translates cron expressions into plain English.
Understanding the Five-Field Cron Format
Every cron expression consists of five fields separated by spaces:
ββββββββββββββ minute (0-59)
β ββββββββββββββ hour (0-23)
β β ββββββββββββββ day of month (1-31)
β β β ββββββββββββββ month (1-12)
β β β β ββββββββββββββ day of week (0-7, 0 and 7 = Sunday)
β β β β β
* * * * *
Each field accepts specific values, ranges (1-5), lists (1,3,5), steps (*/5), and wildcards (*). Understanding these operators is the key to mastering cron scheduling.
Common Cron Expression Patterns
Here are the most frequently used patterns in production environments:
*/5 * * * * Every 5 minutes
0 * * * * Every hour at minute 0
0 */2 * * * Every 2 hours
0 9 * * * Daily at 9:00 AM
0 9 * * 1-5 Weekdays at 9:00 AM
0 0 * * 0 Weekly on Sunday midnight
0 0 1 * * Monthly on the 1st at midnight
0 0 1 1 * Yearly on January 1st
30 2 * * * Daily at 2:30 AM (common for backups)
Special Cron Expressions
Most cron implementations support convenient shorthand expressions:
@yearly(or@annually) β equivalent to0 0 1 1 *@monthlyβ equivalent to0 0 1 * *@weeklyβ equivalent to0 0 * * 0@daily(or@midnight) β equivalent to0 0 * * *@hourlyβ equivalent to0 * * * *@rebootβ runs once at system startup
Advanced Cron Patterns
0 9-17 * * 1-5 Business hours (9-5 Mon-Fri)
*/15 * * * * Every 15 minutes
0 0 1,15 * * 1st and 15th of each month
0 6 * * 1 Every Monday at 6:00 AM
0 */6 * * * Every 6 hours (midnight, 6, 12, 18)
Parsing Cron Expressions Programmatically
For automated cron expression analysis, use our parser tool:
pip install dargslan-cron-parser
dargslan-cron explain "*/5 * * * *" # "Every 5 minutes"
dargslan-cron next "0 2 * * *" # Next 5 scheduled runs
dargslan-cron validate "0 25 * * *" # Validate (catches hour=25 error)
Crontab Management Best Practices
- Always test cron expressions with a dry run before deploying
- Redirect stdout/stderr to log files:
0 2 * * * /script.sh >> /var/log/cron.log 2>&1 - Use absolute paths for all commands in crontab
- Set PATH and SHELL at the top of your crontab
- Avoid overlapping schedules β use flock for mutual exclusion
- Monitor cron job execution with alerting on failure
Download our free Crontab Expression Parsing Cheat Sheet for a quick syntax reference. For deeper Linux automation knowledge, browse our Linux & DevOps eBooks.