Advanced Cron Syntax: 15 Practical Examples for Every Schedule
2026-06-18
Beyond Basic Cron
Once you know the 5-field format, the real challenge is crafting the right expression for your use case. Here are advanced patterns with explanations.
Common Advanced Patterns
| Pattern | Expression | When It Runs |
|---|---|---|
| Every 15 minutes | `*/15 * * * *` | :00, :15, :30, :45 |
| Every 90 minutes | `0 */90 * * *` (not supported — see below) | — |
| Every 2 hours | `0 */2 * * *` | Midnight, 2AM, 4AM... |
| Every 6 hours | `0 */6 * * *` | Midnight, 6AM, Noon, 6PM |
| Twice daily at specific times | `0 8,20 * * *` | 8:00 AM and 8:00 PM |
| Every weekday at 9:30 AM | `30 9 * * 1-5` | Weekdays only |
| Every Monday and Thursday | `0 0 * * 1,4` | Midnight Mon & Thu |
| First day of every month | `0 0 1 * *` | Midnight on the 1st |
| Every 15th and last day | `0 0 15,L * *` | Midnight 15th and last day |
| Every quarter (Jan, Apr, Jul, Oct) | `0 0 1 1,4,7,10 *` | First of quarter months |
Important: Step Values and Limits
Cron step values like `*/90` for minutes **do not work as expected**. The minute field only supports 0-59. `*/90` would evaluate to `0` (since 90 ≥ 60, it wraps). For intervals longer than 59 minutes, use specific hour/minute combinations:
# Every 90 minutes — not natively possible
# Workaround: use two explicit times
0 0,2,4,6,8,10,12,14,16,18,20,22 * * *
30 1,3,5,7,9,11,13,15,17,19,21,23 * * *
Real-World Examples
Database Backup Every Hour
0 * * * * /usr/bin/pg_dump mydb > /backups/db.sql
0 * * * * /usr/bin/pg_dump mydb > /backups/db.sqlLog Rotation at Midnight
0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf
0 0 * * * /usr/sbin/logrotate /etc/logrotate.confHealth Check Every 5 Minutes
*/5 * * * * curl -sS https://example.com/health
*/5 * * * * curl -sS https://example.com/healthMonthly Report on the 1st at 3 AM
0 3 1 * * /opt/scripts/generate-report.sh
0 3 1 * * /opt/scripts/generate-report.shMultiple Schedules in One Crontab
# Clean temp files every 6 hours
0 */6 * * * /usr/bin/find /tmp -type f -atime +1 -delete
# Send digest email at 8 AM weekdays
0 8 * * 1-5 /opt/send-digest.sh
# Full system audit on the 1st of every quarter
0 2 1 1,4,7,10 * /opt/audit.sh
# Clean temp files every 6 hours
0 */6 * * * /usr/bin/find /tmp -type f -atime +1 -delete
# Send digest email at 8 AM weekdays
0 8 * * 1-5 /opt/send-digest.sh
# Full system audit on the 1st of every quarter
0 2 1 1,4,7,10 * /opt/audit.shTest Your Cron Expressions
Use the Cron Parser tool on YZIF to instantly decode any cron expression. Paste in your pattern and see exactly when it will fire, in both English and Chinese.