Cron and Crontab: Scheduling Tasks

Cron runs tasks at fixed times. Every user has their own crontab.

Syntax

# min  hour day  mon  weekday  command
*/30 * * * *     /path/script.sh
0 9 * * 1-5      /path/morning.sh
0 2 * * 0        /path/weekend.sh

Editing

crontab -e to edit, crontab -l to list, crontab -r to remove.

Important notes

  • Environment variables are often missing — use absolute paths.
  • Redirect output to a log file: >> /var/log/mine.log 2>&1.
  • No feedback on errors — add logging.
  • For systems that do not run 24/7: anacron or systemd timers (OnCalendar).

systemd timer as alternative

[Unit]
Description=My timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target

See also: System Administration.