Skip to main content
๐ŸŽ“ Claude Code Masterclass Learn AI-assisted development on Udemy โ€” plus the companion book on Leanpub & Amazon. Start Learning
Cron Cheat Sheet: Schedule Syntax and Examples
DevOps

Cron Cheat Sheet: Schedule Syntax and Examples

Cron cheat sheet with syntax, examples, and common schedules. crontab editing, logging, debugging, systemd timers comparison, and 20+ ready-to-use expressions.

LB
Luca Berton
ยท 1 min read

A quick reference for cron โ€” Linux job scheduling. Bookmark this page.

Crontab Commands

# Edit your crontab
crontab -e

# List your crontab
crontab -l

# Edit another user's crontab
sudo crontab -u username -e

# Remove your crontab
crontab -r

Cron Syntax

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ minute (0-59)
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ hour (0-23)
โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of month (1-31)
โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ month (1-12)
โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ day of week (0-7, 0 and 7 = Sunday)
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
* * * * * command

Common Schedules

# Every minute
* * * * * /usr/local/bin/check.sh

# Every 5 minutes
*/5 * * * * /usr/local/bin/monitor.sh

# Every hour at minute 0
0 * * * * /usr/local/bin/hourly.sh

# Daily at 2:30 AM
30 2 * * * /usr/local/bin/backup.sh

# Weekly on Monday at 9 AM
0 9 * * 1 /usr/local/bin/weekly-report.sh

# Monthly on the 1st at midnight
0 0 1 * * /usr/local/bin/monthly-cleanup.sh

# Weekdays at 8 AM
0 8 * * 1-5 /usr/local/bin/workday.sh

# Every 15 minutes during business hours
*/15 8-17 * * 1-5 /usr/local/bin/business-check.sh

# Twice daily at 6 AM and 6 PM
0 6,18 * * * /usr/local/bin/sync.sh

Special Strings

@reboot    /usr/local/bin/startup.sh    # Run once at boot
@hourly    /usr/local/bin/hourly.sh     # 0 * * * *
@daily     /usr/local/bin/daily.sh      # 0 0 * * *
@weekly    /usr/local/bin/weekly.sh     # 0 0 * * 0
@monthly   /usr/local/bin/monthly.sh    # 0 0 1 * *
@yearly    /usr/local/bin/yearly.sh     # 0 0 1 1 *

Best Practices

# Always use full paths
0 2 * * * /usr/bin/python3 /opt/scripts/backup.py

# Redirect output to log
0 2 * * * /opt/scripts/backup.sh >> /var/log/backup.log 2>&1

# Suppress output (if using email notifications)
0 2 * * * /opt/scripts/quiet-task.sh > /dev/null 2>&1

# Set environment variables
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
MAILTO=admin@example.com

# Use flock to prevent overlapping runs
*/5 * * * * /usr/bin/flock -n /tmp/job.lock /opt/scripts/slow-job.sh

System Cron Directories

/etc/cron.d/          # System cron jobs (with user field)
/etc/cron.daily/      # Scripts run daily
/etc/cron.hourly/     # Scripts run hourly
/etc/cron.weekly/     # Scripts run weekly
/etc/cron.monthly/    # Scripts run monthly

Tips and Tricks

  • Use crontab.guru to validate cron expressions
  • Use flock to prevent concurrent execution of long-running jobs
  • Set MAILTO="" to disable email notifications
  • Use systemd timers instead of cron for better logging (see SystemD Cheat Sheet)
  • Check /var/log/cron or journalctl -u crond for cron execution logs

Free 30-min AI & Cloud consultation

Book Now