Cron Expression Guide: Syntax, Examples & Common Schedules

Updated March 2026 · 7 min read

Cron is the time-based job scheduler used in Unix-like operating systems to automate repetitive tasks. From log rotation and database backups to deployment scripts and health checks, cron jobs are ubiquitous in system administration and DevOps. This guide covers the syntax, provides ready-to-use examples, and helps you avoid common pitfalls.

Cron Syntax: The 5 Fields

A standard cron expression consists of five fields separated by spaces:

*     *     *     *     *
|     |     |     |     |
|     |     |     |     +-- Day of Week (0-7, 0 and 7 = Sunday)
|     |     |     +-------- Month (1-12)
|     |     +-------------- Day of Month (1-31)
|     +-------------------- Hour (0-23)
+-------------------------- Minute (0-59)

Special Characters

CharacterMeaningExample
*Any value* * * * * = every minute
,List of values1,15 * * * * = minute 1 and 15
-Range1-5 * * * * = minutes 1 through 5
/Step/interval*/5 * * * * = every 5 minutes

Common Cron Schedules

ExpressionDescription
* * * * *Every minute
*/5 * * * *Every 5 minutes
*/15 * * * *Every 15 minutes
0 * * * *Every hour (at minute 0)
0 */6 * * *Every 6 hours
0 0 * * *Daily at midnight
0 9 * * *Daily at 9:00 AM
0 9 * * 1-5Weekdays at 9:00 AM
0 0 * * 0Weekly on Sunday at midnight
0 0 * * 1Weekly on Monday at midnight
0 0 1 * *First day of every month at midnight
0 0 1 1 *January 1st at midnight (yearly)
30 2 * * *Daily at 2:30 AM
0 0 15 * *15th of every month at midnight
0 8-17 * * 1-5Every hour, 8AM-5PM, Mon-Fri

Predefined Shortcuts

Many cron implementations support these convenient shortcuts:

ShortcutEquivalentDescription
@yearly0 0 1 1 *Once a year
@monthly0 0 1 * *Once a month
@weekly0 0 * * 0Once a week
@daily0 0 * * *Once a day
@hourly0 * * * *Once an hour
@rebootN/ARun once at startup

Real-World Cron Job Examples

Database Backup (Daily at 2 AM)

0 2 * * * /usr/local/bin/backup-db.sh >> /var/log/backup.log 2>&1

SSL Certificate Renewal Check (Twice Daily)

0 0,12 * * * certbot renew --quiet

Monitor your certificate expiry with the SSL Certificate Checker.

Log Rotation (Weekly)

0 0 * * 0 /usr/sbin/logrotate /etc/logrotate.conf

Health Check (Every 5 Minutes)

*/5 * * * * curl -sf https://devtoolkit.ink/api/v1/health || alert.sh

Clean Temporary Files (Daily at 3 AM)

0 3 * * * find /tmp -type f -mtime +7 -delete

Managing Cron Jobs

# Edit your crontab
crontab -e

# List current cron jobs
crontab -l

# Remove all cron jobs (careful!)
crontab -r

# Edit another user's crontab (as root)
crontab -u username -e

# System-wide cron jobs
ls /etc/cron.d/
ls /etc/cron.daily/
ls /etc/cron.hourly/

Common Cron Mistakes

1. Forgetting the PATH

Cron runs with a minimal environment. Commands that work in your shell may fail in cron because /usr/local/bin is not in the cron PATH.

# Fix: use absolute paths
0 * * * * /usr/local/bin/node /home/user/script.js

# Or set PATH at the top of your crontab
PATH=/usr/local/bin:/usr/bin:/bin
0 * * * * node /home/user/script.js

2. Not Redirecting Output

By default, cron emails output to the user. If mail is not configured, output is lost. Always redirect to a log file:

# Redirect stdout and stderr to a log file
0 * * * * /scripts/task.sh >> /var/log/task.log 2>&1

# Discard output entirely
0 * * * * /scripts/task.sh > /dev/null 2>&1

3. Timezone Confusion

Cron uses the system timezone by default. If your server is in UTC but you expect local time, jobs run at unexpected hours. Check with timedatectl and convert timestamps using the Unix Timestamp Converter.

4. Day-of-Month and Day-of-Week Conflict

When both day-of-month and day-of-week are specified (not *), cron runs the job when either condition is true, not both. This catches many people off guard:

# Runs on the 15th AND every Friday (not just Friday the 15th)
0 0 15 * 5 /scripts/task.sh

# To run only on Friday the 15th, use a wrapper:
0 0 15 * * [ "$(date +\%u)" = "5" ] && /scripts/task.sh

5. Overlapping Executions

If a job takes longer than the interval between runs, multiple instances stack up. Use flock to prevent overlap:

*/5 * * * * flock -n /tmp/task.lock /scripts/long-task.sh

Cron Alternatives

FAQ

What is the difference between 5-field and 6-field cron?

Standard Unix cron uses 5 fields (minute through day-of-week). Some systems like Quartz, Spring, and AWS add a 6th field for seconds. The DevToolKit Cron Parser supports the standard 5-field format.

Can cron run a job every 30 seconds?

Cron's minimum resolution is 1 minute. For sub-minute scheduling, use two cron entries offset by 30 seconds, or switch to systemd timers or a dedicated scheduler.

How do I debug a cron job that is not running?

Check /var/log/syslog or /var/log/cron for execution records. Verify permissions, PATH, and ensure the script is executable (chmod 755).

Try Cron Expression Parser Now →

DevToolKit — 42+ Free Online Developer Tools