Bird
Raised Fist0
Linux CLIscripting~20 mins

systemd timers in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Systemd Timer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of systemd timer status command
What is the output of the command systemctl status mytask.timer if the timer is active and scheduled to run the next job in 10 minutes?
Linux CLI
systemctl status mytask.timer
A
● mytask.timer - Run mytask periodically
   Loaded: loaded (/etc/systemd/system/mytask.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Fri 2024-06-21 10:00:00 UTC; 5min ago
   Trigger: Fri 2024-06-21 10:15:00 UTC; 10min left
B
● mytask.timer - Run mytask periodically
   Loaded: loaded (/etc/systemd/system/mytask.timer; disabled; vendor preset: enabled)
   Active: inactive (dead)
C
● mytask.timer - Run mytask periodically
   Loaded: loaded (/etc/systemd/system/mytask.timer; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2024-06-21 09:50:00 UTC; 15min ago
D
● mytask.timer - Run mytask periodically
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
Attempts:
2 left
💡 Hint
Look for the 'Active: active (waiting)' status and the next trigger time.
🧠 Conceptual
intermediate
2:00remaining
Understanding systemd timer units and service units
Which statement correctly describes the relationship between a systemd timer unit and its corresponding service unit?
ATimer units and service units are independent and do not interact.
BA service unit schedules the timer unit to run at specific times.
CA timer unit triggers the execution of its linked service unit according to the schedule defined in the timer.
DA timer unit replaces the need for a service unit entirely.
Attempts:
2 left
💡 Hint
Think about what triggers the service execution in systemd timers.
📝 Syntax
advanced
2:00remaining
Identify the correct OnCalendar syntax for a systemd timer
Which option correctly sets a systemd timer to run every day at 3:30 AM using the OnCalendar directive?
Linux CLI
[Timer]
OnCalendar=???
Adaily 03:30
B03:30 daily
Cdaily
D03:30:00
Attempts:
2 left
💡 Hint
OnCalendar uses a specific time format like 'HH:MM:SS' or calendar events.
🔧 Debug
advanced
2:00remaining
Why does this systemd timer not trigger the service?
Given the following timer unit file, why does the timer never trigger the service? [Unit] Description=Run backup daily [Timer] OnCalendar=daily Persistent=true [Install] WantedBy=timers.target
Linux CLI
[Service]
ExecStart=/usr/local/bin/backup.sh
AThe timer unit file is missing the [Service] section; the service is not defined here.
BThe OnCalendar=daily syntax is invalid and causes the timer to fail silently.
CThe Persistent=true option disables the timer from running if missed.
DThe WantedBy=timers.target is incorrect; it should be multi-user.target.
Attempts:
2 left
💡 Hint
Timers trigger service units, but the service unit must be defined separately.
🚀 Application
expert
3:00remaining
Create a systemd timer to run a script every 15 minutes starting at 5 minutes past the hour
Which OnCalendar value correctly schedules a systemd timer to run every 15 minutes starting at 5 minutes past each hour (e.g., 00:05, 00:20, 00:35, 00:50)?
AOnCalendar=*-*-* *:05,20,35,50:00
BOnCalendar=*-*-* *:05/15:00
COnCalendar=*-*-* *:5/15:00
DOnCalendar=*:05/15:00
Attempts:
2 left
💡 Hint
Use the format 'HH:MM/interval:SS' with leading zeros for minutes.

Practice

(1/5)
1. What is the main purpose of a systemd timer in Linux?
easy
A. To manage user permissions
B. To schedule and run tasks automatically at specified times
C. To monitor system hardware status
D. To update software packages automatically

Solution

  1. Step 1: Understand systemd timer role

    Systemd timers are designed to schedule tasks to run automatically without manual intervention.
  2. Step 2: Compare with other options

    Monitoring hardware, managing permissions, and updating packages are not the primary roles of systemd timers.
  3. Final Answer:

    To schedule and run tasks automatically at specified times -> Option B
  4. Quick Check:

    Systemd timers = schedule tasks [OK]
Hint: Timers schedule tasks like alarms for programs [OK]
Common Mistakes:
  • Confusing timers with monitoring tools
  • Thinking timers manage user permissions
  • Assuming timers update software automatically
2. Which of the following is the correct syntax to enable a systemd timer named backup.timer?
easy
A. systemctl enable backup.timer
B. systemctl start backup.timer
C. systemctl run backup.timer
D. systemctl activate backup.timer

Solution

  1. Step 1: Identify enabling command for systemd timers

    The command systemctl enable sets a timer to start automatically on boot.
  2. Step 2: Differentiate from other commands

    start runs the timer immediately but does not enable it; run and activate are invalid commands.
  3. Final Answer:

    systemctl enable backup.timer -> Option A
  4. Quick Check:

    Enable timer = systemctl enable [OK]
Hint: Use 'enable' to start timer on boot, 'start' to run now [OK]
Common Mistakes:
  • Using 'start' instead of 'enable' to auto-run timers
  • Using invalid commands like 'run' or 'activate'
  • Confusing service commands with timer commands
3. Given this timer unit file snippet:
[Timer]
OnCalendar=*-*-* 12:00:00
Persistent=true

What does the Persistent=true setting do?
medium
A. Prevents the timer from running at boot
B. Runs the timer only once
C. Disables the timer after one run
D. Runs missed jobs immediately after boot

Solution

  1. Step 1: Understand Persistent=true meaning

    This setting makes systemd run any missed timer jobs immediately after the system boots.
  2. Step 2: Eliminate other options

    It does not limit runs to once, disable timers, or prevent running at boot.
  3. Final Answer:

    Runs missed jobs immediately after boot -> Option D
  4. Quick Check:

    Persistent=true = catch missed runs after reboot [OK]
Hint: Persistent=true runs missed tasks after reboot [OK]
Common Mistakes:
  • Thinking it runs only once
  • Assuming it disables timer after run
  • Believing it prevents timer at boot
4. You created a timer file cleanup.timer but it never triggers the service. Which is the most likely mistake?
medium
A. The timer file is not named exactly like the service file
B. The timer file is missing the [Timer] section
C. The service file cleanup.service is not enabled
D. The timer file uses OnBootSec= instead of OnCalendar=

Solution

  1. Step 1: Check timer and service file naming

    Systemd timers must have matching names with their service files except for the extension.
  2. Step 2: Analyze other options

    Missing [Timer] section causes syntax errors; service enabling is not required for timers to trigger; both OnBootSec and OnCalendar are valid.
  3. Final Answer:

    The timer file is not named exactly like the service file -> Option A
  4. Quick Check:

    Timer and service names must match [OK]
Hint: Timer and service filenames must match except extension [OK]
Common Mistakes:
  • Ignoring filename matching between timer and service
  • Assuming service must be enabled for timer to run
  • Confusing valid timer options as errors
5. You want a systemd timer to run a backup service every day at 3:30 AM but only if the system was off at that time. Which timer configuration achieves this?
hard
A. [Timer] OnActiveSec=03:30:00 Persistent=true
B. [Timer] OnCalendar=*-*-* 03:30:00 AccuracySec=1min
C. [Timer] OnCalendar=*-*-* 03:30:00 Persistent=true
D. [Timer] OnBootSec=03:30:00 Persistent=false

Solution

  1. Step 1: Identify daily schedule at 3:30 AM

    The OnCalendar=*-*-* 03:30:00 sets the timer to run daily at 3:30 AM.
  2. Step 2: Ensure missed runs execute after downtime

    Persistent=true makes systemd run missed jobs after system was off at scheduled time.
  3. Step 3: Evaluate other options

    AccuracySec adjusts timing precision but doesn't affect missed runs; OnBootSec and OnActiveSec run relative to boot or activation, not fixed time.
  4. Final Answer:

    [Timer] OnCalendar=*-*-* 03:30:00 Persistent=true -> Option C
  5. Quick Check:

    Daily 3:30 AM with catch-up = OnCalendar + Persistent [OK]
Hint: Use OnCalendar with Persistent=true for daily missed runs [OK]
Common Mistakes:
  • Using OnBootSec instead of OnCalendar for fixed time
  • Forgetting Persistent=true to run missed jobs
  • Confusing AccuracySec with scheduling behavior
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard