Cron Expression Translator - From Human Language to Cron and Back
Cron expressions are the standard way to schedule recurring tasks in Unix-like systems, CI/CD pipelines, cloud services, and application schedulers. However, the syntax can be cryptic: what does */5 * * * * mean? And how do you express "every weekday at 9 AM"?
This guide provides a practical translator between human-readable schedules and cron syntax, with real-world examples, common patterns, and tips for avoiding mistakes.
Cron Expression Structure
A standard cron expression has five or six fields (depending on the system):
┌─────── minute (0 - 59)
│ ┌───── hour (0 - 23)
│ │ ┌─── day of month (1 - 31)
│ │ │ ┌─ month (1 - 12)
│ │ │ │ ┌ day of week (0 - 6) (Sunday = 0 or 7)
│ │ │ │ │
* * * * *Some systems (like Quartz Scheduler) add a seconds field at the beginning:
┌────── second (0 - 59)
│ ┌──── minute (0 - 59)
│ │ ┌── hour (0 - 23)
│ │ │ ┌ day of month (1 - 31)
│ │ │ │ ┌ month (1 - 12)
│ │ │ │ │ ┌ day of week (0 - 6)
│ │ │ │ │ │
* * * * * *Common Patterns: Human to Cron
Every N Minutes
| Human | Cron |
|---|---|
| Every minute | * * * * * |
| Every 5 minutes | */5 * * * * |
| Every 15 minutes | */15 * * * * |
| Every 30 minutes | */30 * * * * |
Every N Hours
| Human | Cron |
|---|---|
| Every hour | 0 * * * * |
| Every 2 hours | 0 */2 * * * |
| Every 6 hours | 0 */6 * * * |
| Every 12 hours | 0 */12 * * * |
Daily Schedules
| Human | Cron |
|---|---|
| Every day at midnight | 0 0 * * * |
| Every day at 9 AM | 0 9 * * * |
| Every day at 5:30 PM | 30 17 * * * |
| Twice daily (9 AM and 5 PM) | 0 9,17 * * * |
Weekly Schedules
| Human | Cron |
|---|---|
| Every Monday at 9 AM | 0 9 * * 1 |
| Every Friday at 5 PM | 0 17 * * 5 |
| Every weekday at 8 AM | 0 8 * * 1-5 |
| Every weekend at 10 AM | 0 10 * * 0,6 |
Monthly Schedules
| Human | Cron |
|---|---|
| First day of month at midnight | 0 0 1 * * |
| Last day of month | 0 0 L * * (non-standard, use alternative) |
| 15th of every month at 2 PM | 0 14 15 * * |
| First Monday of every month | 0 0 * * 1#1 (Quartz syntax) |
Cron Syntax Elements
Asterisk (*) - Any Value
* * * * *
↑
Every minute
* 9 * * *
↑
Every minute between 9:00 and 9:59Comma (,) - Value List
0 9,12,17 * * *
↑
At 9 AM, 12 PM, and 5 PM
0 0 * * 1,3,5
↑
Every Monday, Wednesday, and Friday at midnightHyphen (-) - Range
0 9-17 * * *
↑
Every hour from 9 AM to 5 PM
0 0 * * 1-5
↑
Every weekday (Monday through Friday) at midnightSlash (/) - Step Values
*/5 * * * *
↑
Every 5 minutes
0 */2 * * *
↑
Every 2 hours (at minute 0)
0 9-17/2 * * *
↑
Every 2 hours between 9 AM and 5 PM (9, 11, 13, 15, 17)Real-World Examples
Example 1: Backup System
# Incremental backups every 4 hours
0 */4 * * *
# Full backup every Sunday at 2 AM
0 2 * * 0
# Database backup every day at 1 AM
0 1 * * *Example 2: CI/CD Pipeline
# Run tests every 15 minutes during work hours (9 AM - 5 PM, weekdays)
*/15 9-17 * * 1-5
# Deploy to staging every weekday at 6 PM
0 18 * * 1-5
# Clean up old builds every day at 3 AM
0 3 * * *Example 3: Monitoring and Alerts
# Health check every minute
* * * * *
# Generate hourly reports
0 * * * *
# Send daily summary at 8 AM
0 8 * * *
# Weekly report every Monday at 9 AM
0 9 * * 1Example 4: Data Processing
# Process queue every 5 minutes
*/5 * * * *
# ETL job every night at midnight
0 0 * * *
# Archive old data on first of month at 2 AM
0 2 1 * *Common Mistakes and Edge Cases
Mistake 1: Both Day Fields Active
When both day-of-month and day-of-week are specified (not *), the job runs when either condition matches:
# This runs on the 15th of every month AND every Friday
0 0 15 * 5
# Not just Friday the 15th!To run only on Friday the 15th, you need external logic in your script.
Mistake 2: Step Values Don't Guarantee Alignment
# This runs at :00, :05, :10, :15, :20, :25, :30, :35, :40, :45, :50, :55
*/5 * * * *
# NOT at arbitrary "every 5 minutes from when started"Cron always aligns to clock boundaries. */5 means "when minute mod 5 equals 0."
Mistake 3: Month and Day Ranges
# Valid: January through March
0 0 1 1-3 *
# Invalid: Wrapping around (Nov-Feb)
0 0 1 11-2 * # Doesn't work as expected
# Correct way to handle year wrapping:
0 0 1 11,12,1,2 *Mistake 4: Timezone Confusion
Cron runs in the system's local timezone (or container timezone). When deploying across regions:
- Verify timezone with
dateortimedatectl - Use UTC for consistency across servers
- Document timezone in cron comments
System-Specific Variations
Standard Unix Cron (5 fields)
# Format: minute hour day month day-of-week
*/5 * * * * /path/to/script.shQuartz Scheduler (6-7 fields)
# Format: second minute hour day month day-of-week [year]
0 */5 * * * ? * # Every 5 minutes
# The '?' means "no specific value" and is required when day-of-month or day-of-week is specifiedAWS EventBridge
# Format: minute hour day month day-of-week year
# Uses 6 fields with year
*/5 * * * ? * # Every 5 minutesGitHub Actions
# Standard 5-field cron
on:
schedule:
- cron: '*/15 * * * *' # Every 15 minutesTesting Cron Expressions
Before deploying cron jobs to production, validate them using the DevToys Pro Cron Parser:
- Translate between cron syntax and human-readable descriptions
- Preview next runs to verify the schedule matches your intent
- Validate syntax before adding to crontab
- Test edge cases like month boundaries and leap years
Practical Tips
1. Use Comments in Crontab
# Backup database every night at 2 AM
0 2 * * * /scripts/backup.sh
# Clean temp files every Sunday at 3 AM
0 3 * * 0 /scripts/cleanup.sh
# Send weekly report every Monday at 9 AM
0 9 * * 1 /scripts/report.sh2. Log Output for Debugging
# Redirect output to log file
*/5 * * * * /scripts/job.sh >> /var/log/job.log 2>&1
# Log with timestamp
*/5 * * * * echo "$(date): Running job" >> /var/log/job.log; /scripts/job.sh3. Handle Job Overlaps
# Use flock to prevent concurrent runs
*/5 * * * * flock -n /var/lock/job.lock /scripts/job.sh
# Or check for existing process
*/5 * * * * pgrep -f job.sh || /scripts/job.sh4. Test Locally Before Deployment
# Temporarily change to every minute for testing
* * * * * /scripts/job.sh
# After verification, change to production schedule
0 2 * * * /scripts/job.shAlternatives to Complex Cron
For complex schedules, consider these alternatives:
- Systemd timers (Linux) - More flexible than cron
- Task schedulers - Celery Beat, APScheduler for Python
- Cloud schedulers - AWS EventBridge, GCP Cloud Scheduler
- Orchestration tools - Apache Airflow for complex workflows
Conclusion
Cron expressions provide a powerful, standardized way to schedule recurring tasks. Key takeaways:
- Learn the five-field structure: minute, hour, day, month, day-of-week
- Use
*for any value,,for lists,-for ranges,/for steps - Be aware of timezone and system-specific syntax variations
- Test expressions before production deployment
- Document complex schedules with comments
- Watch for edge cases like overlapping day conditions
Use the Cron Parser to translate between human language and cron syntax, validate expressions, and preview next execution times.