Skip to content
# Automation & security

Cron and scheduled tasks

Run a command on a schedule with cron or a modern systemd timer.

Edit your crontab

Each user has their own crontab. crontab -e opens it in your default editor; crontab -l lists the current entries without editing.

bash
crontab -e
crontab -l

Cron time syntax

Five fields, in order: minute, hour, day-of-month, month, day-of-week β€” then the command. * means "every".

text
# m h dom mon dow  command
0 3 * * *      /usr/local/bin/backup.sh     # every day at 03:00
*/15 * * * *   /usr/local/bin/healthcheck.sh # every 15 minutes
0 0 1 * *      /usr/local/bin/monthly.sh    # 1st of the month, midnight

System-wide cron and run-parts directories

For scripts that should run regardless of which user owns them, drop an executable script into /etc/cron.daily, /etc/cron.hourly, etc. β€” no crontab syntax needed, just chmod +x it.

bash
sudo cp backup.sh /etc/cron.daily/backup
sudo chmod +x /etc/cron.daily/backup

systemd timers: cron's modern alternative

On systemd distros, a .timer unit paired with a .service unit does the same job with better logging (journalctl -u) and dependency handling. More setup than a crontab line, but worth it for anything you need to debug when it fails silently.

text
# /etc/systemd/system/backup.timer
[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target