What Is Cron?
Cron is a time-based job scheduler on Linux. It runs commands or scripts at specified intervals — every minute, hourly, daily, weekly, or on custom schedules.
Crontab Format
# ┌───────── minute (0-59)
# │ ┌───────── hour (0-23)
# │ │ ┌───────── day of month (1-31)
# │ │ │ ┌───────── month (1-12)
# │ │ │ │ ┌───────── day of week (0-7, 0 and 7 = Sunday)
# │ │ │ │ │
# * * * * * commandManaging Crontab
# Edit your crontab
crontab -e
# List current crontab
crontab -l
# Edit another user's crontab (as root)
crontab -u www-data -eCommon Examples
# Every day at 3:00 AM
0 3 * * * /usr/local/bin/backup.sh
# Every 5 minutes
*/5 * * * * /usr/local/bin/check-health.sh
# Every Monday at 9 AM
0 9 * * 1 /usr/local/bin/weekly-report.sh
# First day of every month at midnight
0 0 1 * * /usr/local/bin/monthly-cleanup.sh
# Every weekday (Mon-Fri) at 8 AM
0 8 * * 1-5 /usr/local/bin/daily-digest.shShortcuts
@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 * *Logging Output
# Log output to a file
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
# Discard output (no email)
*/5 * * * * /usr/local/bin/check.sh > /dev/null 2>&1Common Pitfalls
- Cron uses a minimal PATH — use full paths for commands
- Cron does not load your shell profile — set environment variables in the crontab
- Make scripts executable:
chmod +x script.sh - Use
2>&1to capture both stdout and stderr