About Cron Expressions
Cron expressions are used to schedule tasks to run at specific times or intervals. They consist of 5 fields representing minute, hour, day of month, month, and day of week.
Cron Expression Format
* * * * *
β β β β β
β β β β ββββ Day of Week (0-6, Sunday=0)
β β β ββββββ Month (1-12)
β β ββββββββ Day of Month (1-31)
β ββββββββββ Hour (0-23)
ββββββββββββ Minute (0-59)
β β β β β
β β β β ββββ Day of Week (0-6, Sunday=0)
β β β ββββββ Month (1-12)
β β ββββββββ Day of Month (1-31)
β ββββββββββ Hour (0-23)
ββββββββββββ Minute (0-59)
Special Characters
| Character | Meaning | Example |
|---|---|---|
| * | Any value | * in minute = every minute |
| , | List of values | 1,15 in minute = minute 1 and 15 |
| - | Range of values | 1-5 in day of week = Mon to Fri |
| / | Step values | */5 in minute = every 5 minutes |
Common Examples
0 0 * * *- Daily at midnight0 */6 * * *- Every 6 hours0 9 * * 1-5- Weekdays at 9 AM0 0 1 * *- First day of every month*/15 * * * *- Every 15 minutes0 0 * * 0- Every Sunday at midnight
Use Cases
- Backup Jobs: Schedule daily or weekly backups
- Report Generation: Generate reports at specific times
- Data Synchronization: Sync data between systems
- Cleanup Tasks: Remove old files or logs periodically
- Monitoring: Run health checks at intervals
- Email Notifications: Send scheduled emails
- Database Maintenance: Run optimization tasks
Tips
- Start with simple mode if you're new to cron expressions
- Use presets as a starting point and customize as needed
- Test your cron expression before deploying to production
- Consider timezone differences when scheduling tasks
- Use */n for interval-based scheduling
- Combine ranges and lists for complex schedules
- Document your cron expressions for team members
Supported Platforms
Cron expressions are widely supported across various platforms including Linux/Unix cron, Jenkins, Kubernetes CronJobs, AWS CloudWatch Events, Azure Functions, Google Cloud Scheduler, and many task scheduling libraries.