Cron expressions are one of those things every developer needs but nobody memorizes. Bookmark this — you'll thank yourself later.
The Format
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-7, Sun=0 or 7)
│ │ │ │ │
* * * * *
Special Characters
| Char | Meaning | Example |
|---|---|---|
* |
Any value |
* * * * * = every minute |
, |
List |
1,15 * * * * = minute 1 and 15 |
- |
Range |
1-5 * * * * = minutes 1 through 5 |
/ |
Step |
*/10 * * * * = every 10 minutes |
Common Schedules You'll Actually Use
Every X minutes
*/5 * * * * # Every 5 minutes
*/15 * * * * # Every 15 minutes
*/30 * * * * # Every 30 minutes
Hourly
0 * * * * # Top of every hour
30 * * * * # Half past every hour
0 */2 * * * # Every 2 hours
0 */6 * * * # Every 6 hours
Daily
0 0 * * * # Midnight
0 9 * * * # 9:00 AM
0 9 * * 1-5 # 9:00 AM, weekdays only
30 2 * * * # 2:30 AM (good for backups)
Weekly
0 0 * * 0 # Midnight Sunday
0 0 * * 1 # Midnight Monday
0 9 * * 1 # 9 AM Monday (weekly report)
0 17 * * 5 # 5 PM Friday (weekly digest)
Monthly
0 0 1 * * # Midnight, 1st of month
0 9 1 * * # 9 AM, 1st of month
0 0 15 * * # Midnight, 15th of month
0 0 1 */3 * # Quarterly (Jan, Apr, Jul, Oct)
Yearly
0 0 1 1 * # Midnight, January 1st
0 9 1 1 * # 9 AM, January 1st
Common Mistakes
❌ * * * * * doesn't mean "once a day"
It means every single minute. That's 1,440 times per day.
❌ Day of week starts at 0 (Sunday)
* * * * 1 = Monday, not Tuesday. Both 0 and 7 mean Sunday.
❌ No second-level precision
Standard cron doesn't support seconds. If you need sub-minute scheduling, use a different tool.
❌ Month and DOW are OR, not AND
0 0 15 * 5 runs on the 15th AND every Friday, not only on Fridays that fall on the 15th.
Validate Before Deploying
Never push a cron expression without checking it first:
# Describe what a cron expression does
curl "https://cronping.anethoth.com/api/v1/cron/describe?expr=*/15+*+*+*+*"
# See the next 5 run times
curl "https://cronping.anethoth.com/api/v1/cron/next?expr=0+9+*+*+1&count=5"
# Validate syntax
curl "https://cronping.anethoth.com/api/v1/cron/validate?expr=0+0+31+2+*"
These are free, no signup required. CronPing Cron API docs
Pro Tips
-
Add randomness for backups: Use
RANDOM=$((RANDOM % 60))sleep to avoid thundering herd -
Log everything:
0 * * * * /path/script.sh >> /var/log/cron.log 2>&1 -
Use
flockto prevent overlap:* * * * * flock -n /tmp/job.lock /path/script.sh - Monitor your crons: A cron that fails silently is worse than no cron at all. Use a dead man's switch to alert when jobs don't run.
-
Test in a non-production environment first:
crontab -lto review,crontab -eto edit
Bookmark this. Star it. Whatever helps you find it when you need it at 3 AM.
What cron schedule do you use most often? Drop it in the comments 👇
Top comments (0)