systemd timers
The modern alternative to cron on most Linux distributions, with better logs and control.
On systems that use systemd, a timer unit starts a service unit on a schedule. Compared with cron you get logging in the journal, dependencies, resource limits and the option to catch up on runs missed while the machine was off.
The service
[Unit]
Description=Nightly backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.shThe timer
[Unit]
Description=Run backup every night
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
[Install]
WantedBy=timers.targetOnCalendaris the schedule. Check an expression withsystemd-analyze calendar "*-*-* 02:30:00".Persistent=trueruns a missed job at the next boot.- The timer and the service share the name by default (
backup.timerstartsbackup.service).
Enable and inspect
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timers
journalctl -u backup.serviceNoteCron is still fine for simple jobs and exists everywhere. Choose timers when you want logs, ordering or catch-up.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.