CompTIA Linux+ (XK0-006)Services and User ManagementHard
A system administrator wants to define a custom `systemd` timer unit named `mytimer.timer` that executes a script `myscript.sh` daily at 2:00 AM. The timer should be persistent across reboots and start automatically. Which of the following `[Timer]` section configurations would correctly achieve this?
- A[Timer] OnBootSec=1min OnUnitActiveSec=24h Persistent=true
- B[Timer] Unit=myscript.service OnCalendar=02:00:00 Persistent=true
- C[Timer] OnCalendar=daily Persistent=true
- D[Timer] OnCalendar=*-*-* 02:00:00 Persistent=true
Show answer & explanationAnswer & explanation
Correct answer: D. [Timer] OnCalendar=*-*-* 02:00:00 Persistent=true
The `OnCalendar=*-*-* 02:00:00` entry specifies a daily execution at 2:00 AM using a calendar event specification. The `Persistent=true` option ensures that if the system is off during a scheduled run, the associated unit will be triggered shortly after the system boots up. This combination correctly addresses both the daily schedule and persistence requirements.
Why the other options are wrong
- A. These options define a timer that runs 1 minute after boot and then 24 hours after the unit last activated, not a fixed daily schedule at 2:00 AM.
- B. The `Unit=myscript.service` option belongs in the `[Timer]` section to specify the service to activate, but `OnCalendar=02:00:00` is incomplete for a daily trigger, as it misses the date components.
- C. `OnCalendar=daily` is a valid shorthand, but it defaults to midnight, not 2:00 AM.
systemd Timer OnCalendar and Persistence
`OnCalendar` defines specific calendar events for timer activation, and `Persistent=true` ensures missed runs are executed after reboot.
- `OnCalendar` uses calendar event specifications (e.g., `*-*-* 02:00:00`).
- `Persistent=true` handles missed timer events after system downtime.
- Timer units activate corresponding service units.
Memory trick: Calendar for 'When', Persistent for 'Missed'.