Lesson 1.60: Timers instead of cron
cron has scheduled jobs on Unix for decades, but its jobs run outside the service manager: no journal, no sandbox, no record of whether the last run worked, and a missed run (the server was off) is simply skipped. A systemd timer is a .timer unit that starts a .service unit on a schedule; the service gets the journal, the sandboxing from 1.2 and status, and Persistent=true catches up missed runs. In the lab you replace web02's nightly backup cron job with a service and timer pair, check the schedule, enable it and test it.
16 min
You will learn to
- Compare cron jobs and systemd timers
- Write a oneshot service and a timer
- Check OnCalendar expressions
- Enable and list timers
- Run the job once and read its journal
Key terms
- Timer unit
- A .timer file that starts a matching .service on a schedule or after a delay.
- OnCalendar=
- A wall-clock schedule in systemd's calendar syntax.
- Persistent=true
- Runs a job missed while the machine was off, as soon as it's back.
- Type=oneshot
- A service that runs to completion and exits, instead of staying running.
- list-timers
- Shows every active timer with its next and last run.
← Kernel, shell and terminal · All lessons · Tracing a failing program with strace →