Find us on social media
CronAutomationTasks5 min read
Schedule tasks with Cron
Schedule automated tasks with Cron to run scripts and commands at defined intervals.
Cron is the standard task scheduler on Linux. Use it to automate backups, maintenance scripts, log rotation and more.
Crontab syntax
terminal
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday)
│ │ │ │ │
* * * * * command_to_executeEdit your crontab
bash
crontab -eChoose your preferred editor (nano is easiest).
Common examples
bash
# Every day at 3:00 AM — database backup
0 3 * * * /home/deploy/scripts/backup-db.sh
# Every hour — clear temp files
0 * * * * rm -rf /tmp/cache/*
# Every Monday at 6:00 AM — system update
0 6 * * 1 sudo apt update && sudo apt upgrade -y
# Every 5 minutes — health check
*/5 * * * * curl -s https://mydomain.com/health > /dev/null
# First day of each month — log rotation
0 0 1 * * /usr/sbin/logrotate /etc/logrotate.confView current crontab
bash
crontab -lRedirect output to a log
bash
0 3 * * * /home/deploy/scripts/backup.sh >> /var/log/backup.log 2>&1System-wide cron jobs
For root-level tasks, edit:
bash
sudo nano /etc/crontabOr place scripts in:
/etc/cron.daily//etc/cron.weekly//etc/cron.monthly/
Special strings
bash
@reboot command # Run once at startup
@daily command # Run once a day (midnight)
@weekly command # Run once a week
@monthly command # Run once a month
@hourly command # Run once an hourTroubleshooting
- Check cron logs:
grep CRON /var/log/syslog - Ensure scripts are executable:
chmod +x script.sh - Use full paths in cron (cron has a minimal PATH)
- Test commands manually before adding to crontab
Was this guide helpful?