FIELD NOTES / UNIX & LINUXNew tools on weekdays. Beyond the man page.
GUEST SERIESPID 1: a week with systemdFrom the Service Manager's Desk · Part 5 of 5
$systemd.timer

systemd.timer: schedule work, then prove what ran

Choose the right clock, make missed-run and jitter behavior explicit, and trace each timer activation into a service result and journal record.

THE DEEP DIVE19 MIN READ
01

A timer waits; another unit does the work

A systemd timer is a unit whose job is to wait for a time condition and activate another unit. It does not contain the maintenance command itself. By default, clitdj-demo.timer activates clitdj-demo.service: the shared basename supplies the pairing. Unit= can name a different unit, but an explicit pairing is easier to inspect than a surprising one. A timer that is active and waiting proves only that the schedule is armed. It does not prove that the service ran successfully.

Read the two definitions below before creating them. [Unit] contains general metadata, and Description gives each unit a readable label. In the service, [Service] holds the execution contract. Type=oneshot means startup includes completion of the command. ExecStart=/usr/bin/true names a harmless executable that exits successfully; systemd does not insert a shell. The service omits RemainAfterExit=yes, so it becomes inactive after completion and can be activated again by a repeating timer.

In the timer, [Timer] holds the scheduling contract. OnCalendar= describes wall-clock occurrences. Unit= makes the activation target explicit. In Mon..Fri *-*-* 09:15:00 UTC, Mon..Fri is the weekday range and *-*-* leaves year, month, and day unrestricted, so the expression says 09:15:00 UTC from Monday through Friday. A timezone belongs to the expression; without one, calendar evaluation uses the host's local timezone. This installment uses the systemd 255 interface and Ubuntu's 255.4-1ubuntu8.17 binaries with Bash 5.2.21. The build container is not running systemd as process ID 1, so parser and file checks are executed below, while manager-dependent commands are clearly labeled unexecuted.

TERMINALUNIT DEFINITIONS
# clitdj-demo.service
[Unit]
Description=Write a synthetic checkpoint
[Service]
Type=oneshot
ExecStart=/usr/bin/true

# clitdj-demo.timer
[Unit]
Description=Run the synthetic checkpoint on weekdays
[Timer]
OnCalendar=Mon..Fri *-*-* 09:15:00 UTC
Unit=clitdj-demo.service

These are two files, not one combined file and not shell commands. Nothing has been installed or activated. The service command does no useful work; that is deliberate. The examples isolate scheduling, activation, and evidence instead of pretending that an application succeeded because its timer elapsed.

02

Validate the calendar before you install it

Calendar expressions are compact enough to misread. Systemd-analyze calendar parses the same expression grammar used by OnCalendar=, normalizes it, and calculates the next elapse. The --base-time option supplies a fixed reference timestamp so the example does not depend on when you read it. The quoted expression is one shell argument; its asterisks therefore reach systemd-analyze instead of being expanded as filenames by Bash.

LC_ALL=C and TZ=UTC are environment assignments that apply to this command and its pipeline. They stabilize English output and timezone display. The vertical bar is a Bash pipe: it sends systemd-analyze's standard output to head. Head's -n 2 option prints at most the first two lines, omitting the time-relative line that would change as time passes. The head deep dive explains that prefix selection; it does not change calendar evaluation.

TERMINALSHELL
LC_ALL=C TZ=UTC systemd-analyze calendar --base-time='2026-11-02 08:00:00 UTC' 'Mon..Fri *-*-* 09:15:00 UTC' | head -n 2
TERMINALEXPECTED STABLE LINES ON SYSTEMD 255
Normalized form: Mon..Fri *-*-* 09:15:00 UTC
    Next elapse: Mon 2026-11-02 09:15:00 UTC

The normalized form confirms the intended weekday rule. The next event is 75 minutes after the supplied base time. This validates syntax and calculation, not installation, enablement, wake-from-suspend behavior, or execution of the associated service. Use --iterations=N to inspect N future occurrences when checking month boundaries, weekdays, or daylight-saving behavior.

03

Build a pair that can be verified without running it

Create the pair only in a new systemd-timer-lab directory below the current directory. Mkdir creates it, and cd enters it. Every setup step is connected with &&, so later writes and verification run only after the earlier step succeeds. If that directory already exists, choose another name and rerun the whole block; do not continue with stale files. Export keeps LC_ALL=C in this shell and its child commands. Umask 022 prevents newly created files from being group- or other-writable.

Each printf command uses the fixed %s\n format: %s consumes the next text argument, and \n ends its line. Single quotes protect unit syntax from Bash, while > creates or replaces only the named fixture file. The printf article develops that fixed-format model. The timer adds [Install], the section used by installation tools. WantedBy=timers.target tells enable to create an installation link so the timer is pulled into the normal timer group; it does not start the timer by itself.

Persistent=true requests one catch-up activation when a calendar occurrence was missed while the timer was inactive. RandomizedDelaySec=15min adds a random delay of up to fifteen minutes, and AccuracySec=1min permits coalescing within a one-minute window. Their different purposes are unpacked below. Systemd-analyze verify loads both supplied files and checks their syntax and references without starting /usr/bin/true. The --man=no option disables manual-page checks, not unit verification.

TERMINALBASH — DISPOSABLE FIXTURE
mkdir systemd-timer-lab &&
cd systemd-timer-lab &&
export LC_ALL=C &&
umask 022 &&
printf '%s\n' '[Unit]' 'Description=Write a synthetic checkpoint' '[Service]' 'Type=oneshot' 'ExecStart=/usr/bin/true' > clitdj-demo.service &&
printf '%s\n' '[Unit]' 'Description=Run the synthetic checkpoint on weekdays' '[Timer]' 'OnCalendar=Mon..Fri *-*-* 09:15:00 UTC' 'Persistent=true' 'RandomizedDelaySec=15min' 'AccuracySec=1min' 'Unit=clitdj-demo.service' '[Install]' 'WantedBy=timers.target' > clitdj-demo.timer &&
systemd-analyze --man=no verify ./clitdj-demo.service ./clitdj-demo.timer &&
printf 'verification succeeded\n'
TERMINALEXPECTED OUTPUT
verification succeeded

Verify itself is silent on success; the final marker prints only because verification returned status zero. The block creates two ordinary files in the new directory and changes the shell's working directory, locale, and umask. It does not contact a service manager, install a unit, create a persistent timestamp, or execute the service. Passing proves neither application correctness nor security.

04

Choose a clock that matches the question

OnCalendar= uses the realtime, or wall, clock: dates, weekdays, times, and timezones matter. Monotonic timers measure elapsed time from a defined event and are independent of wall-clock corrections and timezone changes. OnActiveSec= starts from activation of the timer unit. OnBootSec= starts from machine boot; for the system manager inside a container, systemd maps it to OnStartupSec=. OnStartupSec= starts from the service manager's launch. OnUnitActiveSec= starts from the associated unit's last activation, while OnUnitInactiveSec= starts from its last deactivation.

For a task that should begin ten minutes after boot and then wait an hour after each completion, combine OnBootSec=10min with OnUnitInactiveSec=1h. Multiple expressions are alternatives: the timer elapses when any one becomes due. The 10min and 1h values are time spans; without a unit, these directives interpret numbers as seconds. An explicit suffix makes review easier.

Completion-relative spacing is deliberate. OnUnitActiveSec=1h would measure from activation, so a job that ran for fifty minutes would be eligible again ten minutes after it finished. OnUnitInactiveSec=1h starts the hour when the oneshot becomes inactive. Neither option launches a second copy while the service remains active: if the target unit is already active when a timer elapses, systemd leaves it running rather than restarting it.

TERMINALALTERNATE TIMER DEFINITION
# clitdj-monotonic.timer
[Unit]
Description=Run after boot and after each completed checkpoint
[Timer]
OnBootSec=10min
OnUnitInactiveSec=1h
AccuracySec=1min
Unit=clitdj-demo.service

This definition is an alternative schedule for the same harmless service, not a drop-in to combine with the calendar timer. A service with RemainAfterExit=yes stays active after a successful oneshot and is therefore usually unsuitable for repetitive timer activation. For long-running services, decide explicitly what should happen when the next elapse arrives while work is still active.

05

Verify the monotonic variant as a separate unit

Keep the calendar fixture intact and create the alternate schedule under a different timer name. Test -f checks that the earlier service file exists; && skips the write if setup was not completed. The second timer uses Unit= because its basename no longer matches clitdj-demo.service. Verification receives both files so the intended pair is visible to the checker.

This parser test does not advance a monotonic clock or prove runtime timing. It confirms that the installed systemd 255 build accepts the definitions and can load the supplied relationship. Manager activation remains a separate gate.

TERMINALBASH — SAME DISPOSABLE FIXTURE
test -f clitdj-demo.service &&
printf '%s\n' '[Unit]' 'Description=Run after boot and after each completed checkpoint' '[Timer]' 'OnBootSec=10min' 'OnUnitInactiveSec=1h' 'AccuracySec=1min' 'Unit=clitdj-demo.service' > clitdj-monotonic.timer &&
systemd-analyze --man=no verify ./clitdj-demo.service ./clitdj-monotonic.timer &&
printf 'monotonic verification succeeded\n'
TERMINALEXPECTED OUTPUT
monotonic verification succeeded

The block adds clitdj-monotonic.timer and leaves the calendar pair unchanged. OnBootSec= and OnStartupSec= trigger immediately if their time is already in the past when the timer is activated; the other monotonic directives do not inherit that rule. Monotonic clocks normally pause during suspend unless privileged WakeSystem= behavior selects a different clock. No suspend or wake test was performed here.

06

Catch up once; do not imagine a replay queue

Persistent=true applies only to timers configured with OnCalendar=. Systemd records when the service was last triggered. When the timer becomes active again, it triggers the service if at least one calendar occurrence was missed while the timer was inactive. Ten missed weekdays do not become ten queued service starts; the catch-up is one activation. The catch-up remains subject to RandomizedDelaySec=, so persistent does not mean immediate to the microsecond.

Downtime and suspend are related but different cases. A realtime calendar continues advancing while the machine sleeps. On resume, a calendar timer that elapsed during sleep is processed, but multiple sleep-time occurrences still result in one service activation. Persistent covers a calendar timer that was inactive, including power-off time, by consulting saved state when it is activated later. A monotonic timer normally pauses during suspend and Persistent= does not add catch-up semantics to it.

Catch-up is not evidence that every intended business interval was processed. If the application must handle every missed period, the service needs its own durable checkpoint and replay logic. The timer provides activation, not a transaction ledger. Before removing a persistent timer, systemd 255 recommends cleaning its stored state with systemctl clean --what=state TIMER after the timer has been stopped and when that deletion is authorized. That command changes stored state and is not part of this fixture.

Persistent state can be forensically useful: it helps explain why a service ran shortly after boot even though its nominal wall-clock time had passed. Preserve that context before cleaning it. Conversely, a catch-up activation does not prove the service completed successfully; inspect the service result and journal.

07

Separate coalescing from spreading load

AccuracySec= and RandomizedDelaySec= both move an observed firing away from the nominal time, but for opposite reasons. AccuracySec= defines a window beginning at the calculated elapse. Within that window, the manager chooses a host-specific stable position that can align timers and reduce wake-ups. Its default is one minute. Setting AccuracySec=1us, or one microsecond, asks for the best available precision, still subject to timer slack and scheduling reality.

RandomizedDelaySec= adds an evenly distributed random delay between zero and the configured span before accuracy coalescing is applied. It spreads similar jobs across time to reduce a fleet-wide spike. FixedRandomDelay=true reuses a stable per-timer offset derived from machine, user, and timer identity instead of choosing a new delay for each iteration. That keeps hosts spread apart while reducing each host's jitter.

For a fleet maintenance job, RandomizedDelaySec=15min with FixedRandomDelay=true can distribute starts consistently. If spreading is the primary goal, a tight AccuracySec= such as 1us prevents the later coalescing window from bunching the randomized results again. If power-efficient wake-up coalescing matters more, retain a wider AccuracySec=. There is no universally correct combination; state whether you are optimizing timing precision, wake-ups, or load distribution.

TERMINALFLEET-SPREADING VARIANT
[Timer]
OnCalendar=Mon..Fri *-*-* 09:15:00 UTC
Persistent=true
RandomizedDelaySec=15min
FixedRandomDelay=true
AccuracySec=1us
Unit=clitdj-demo.service

This is a configuration fragment, not a complete file or a command. It replaces the [Timer] settings in the calendar example if stable fleet spreading is the requirement. The actual offset is intentionally not shown as fixed output.

08

Install the timer, not a hopeful service start

The next commands are a live-host recipe for an administrator who has reviewed and deliberately installed the two files as /etc/systemd/system/clitdj-demo.service and /etc/systemd/system/clitdj-demo.timer. The disposable fixture was not installed there, so do not run this expecting its files to appear. Systemctl daemon-reload asks the manager to reread unit definitions and rebuild dependencies. It does not run the service.

Enable --now clitdj-demo.timer performs two actions: enable writes the installation link described by WantedBy=timers.target, and --now also starts the timer immediately. The operand is the timer, not the service. Systemctl list-timers lists timer units currently in manager memory, ordered by their next elapse. --all includes loaded timers without a next elapse, and --no-pager prints directly. The pattern restricts the display to this timer.

Read the columns separately. NEXT and LEFT describe the schedule; LAST and PASSED describe the timer's previous elapse; UNIT names the timer; ACTIVATES names its target. A row with a future NEXT says the timer is waiting. It does not certify the service's last result. Output depends on the current clock, randomized delay, manager state, and previous activations, so no fixed transcript is fabricated.

TERMINALUNEXECUTED LIVE-HOST RECIPE
systemctl daemon-reload
systemctl enable --now clitdj-demo.timer
systemctl --no-pager --all list-timers clitdj-demo.timer

These commands change manager configuration, persistent enablement policy, and runtime timer state. Run them only after installing reviewed files on an authorized systemd host. Enabling a timer is not the same as enabling its service, and starting the service manually does not arm the schedule.

09

Prove the service result, then read its evidence

After an expected elapse, trace the activation into the service. Systemctl show returns machine-oriented properties. The --property option selects Result, ExecMainCode, ExecMainStatus, ActiveState, and SubState. Result summarizes the service outcome. ExecMainCode says how the main process terminated, and ExecMainStatus is interpreted in that context as an exit code or signal. ActiveState and SubState describe current state, which for a completed oneshot can be inactive/dead even after success. The systemctl installment develops those state layers.

Then ask the journal for the service, not only the timer. Journalctl's -b selector chooses the current boot, -u selects records from and about the named unit, -n 20 limits the recent display to twenty entries, and --no-pager prints directly. The journalctl installment explains why boot, unit, time, account, namespace, and retention bound what silence can mean. The timer journal can explain scheduling and activation; the service journal is where command output and process failure normally appear.

Run these queries before reset-failed or cleanup removes useful state. A successful timer elapse followed by a failed service is not a timer success story. Likewise, a quiet journal can reflect retention or permissions rather than no execution.

TERMINALUNEXECUTED LIVE-HOST INSPECTION
systemctl show --property=Result,ExecMainCode,ExecMainStatus,ActiveState,SubState clitdj-demo.service
journalctl --no-pager -b -u clitdj-demo.service -n 20
journalctl --no-pager -b -u clitdj-demo.timer -n 20

All outputs are host-dependent. The first command reads manager state; the next two read accessible journal history. None changes the unit. Preserve the exact timer and service names, clock context, and relevant records when explaining an unexpected run.

10

Use a transient timer when the schedule is temporary

Systemd-run can create a transient timer and service without writing persistent unit files. This is useful for a deliberate one-off delay whose lifecycle should remain in the manager. The --unit=clitdj-transient option supplies the basename, so systemd-run creates clitdj-transient.timer and clitdj-transient.service. --on-active=10min creates a monotonic timer ten minutes after the transient timer becomes active.

The first --timer-property assignment applies AccuracySec=1s to the timer rather than the service. The --property=Type=exec assignment applies to the service. Type=exec does not consider service startup successful until execve() of /usr/bin/true succeeds, rather than treating an earlier fork as sufficient. It does not prove that the program later exits successfully. The final path is the service command. Systemd-run starts the timer now and returns before that future command runs; it cannot be combined with --wait for a timer-triggered service.

This command was not executed in the non-systemd container. On an authorized host, inspect both units immediately after creation with systemctl status or list-timers. Transient does not mean invisible or harmless: the definitions live under manager control, can activate with the caller's authorized service privileges, and may leave failure evidence in memory and the journal.

TERMINALUNEXECUTED LIVE-HOST TRANSIENT TIMER
systemd-run --unit=clitdj-transient --on-active=10min --timer-property=AccuracySec=1s --property=Type=exec /usr/bin/true

Expected informational output names the transient timer and service, but exact wording is version-dependent. This creates runtime state and schedules future execution. Use an explicit, collision-free unit name and record it before relying on automatic cleanup.

11

Explain an unfamiliar timer before changing it

During an authorized configuration review, start with inventory rather than deletion. Systemctl list-timers --all shows loaded timer schedules and their activation targets. Systemctl show selects FragmentPath and DropInPaths for the timer, plus Triggers and TriggeredBy for both sides of the relationship. FragmentPath identifies the main unit file; DropInPaths lists supplemental configuration. Triggers lists units this unit activates, while TriggeredBy lists units that can activate it. Systemctl cat prints the disk-backed main file and drop-ins with filenames; it does not prove that the manager has reloaded a recent edit.

Next inspect the associated service because the timer supplies activation, not a sandbox. Systemd-analyze security evaluates selected service hardening settings and produces an exposure assessment. The --no-pager flag prints directly. A favorable score is not proof that the command, credentials, writable paths, network actions, or application logic are safe. Thursday's service contract supplies the local model: execution identity, filesystem access, capabilities, syscalls, and credentials belong to the service contract.

An unexpected persistent or transient timer can be a legitimate maintenance mechanism, stale configuration, or an unauthorized persistence path. That capability is not itself a vulnerability in systemd and does not establish exploitation. Compare the effective timer and service files with package ownership, approved change records, parent-directory permissions, drop-ins, referenced executables, transient creation history where available, and journal evidence before disabling or removing anything. A writable timer, service, drop-in directory, or executable is a separate trust-boundary finding.

TERMINALUNEXECUTED AUTHORIZED-HOST REVIEW
systemctl --no-pager --all list-timers
systemctl show --property=FragmentPath,DropInPaths,Triggers,TriggeredBy clitdj-demo.timer clitdj-demo.service
systemctl --no-pager cat clitdj-demo.timer clitdj-demo.service
systemd-analyze --no-pager security clitdj-demo.service

These commands inspect manager and file state, although status-style inspection can cause units to be loaded. Results vary. Do not disable, clean, or delete a timer merely because its purpose is unfamiliar; first preserve the relationship, files, permissions, timestamps, package provenance, and relevant journal records.

12

Trace the whole chain, not one green row

A dependable timer has five separately testable claims. The expression identifies when an event is due. The timer is loaded, enabled when boot activation is intended, and active when it should be waiting. The timer points to the intended unit. The service contract performs the intended work with the intended privileges and failure policy. The service result and journal show what actually happened.

The week's model now closes on itself. Monday's unit graph explains why the timer and service are nodes connected by activation and ordering. Tuesday's state inspection separates runtime state, loaded configuration, disk files, and installation policy. Wednesday's journal query supplies bounded evidence. Thursday's service contract defines the work and its trust boundaries. The timer adds time as another activation edge; it does not replace any of those layers.

Before accepting a schedule, state the clock and timezone, initial and repeat triggers, catch-up policy, accuracy and random-delay windows, overlap behavior, activation target, enablement intent, execution privilege, expected result, and evidence path. Then test the calendar, verify the files, inspect the live relationship, and prove the service result. A timer is reliable when the activation contract is explicit and the evidence chain survives the first failure.

The disposable lab contains only ordinary files and can be removed after reviewing the exact path. No recursive cleanup command is provided because the shell's current directory and reader-chosen fixture name are safer to inspect than to assume.

Back to latest issue
HELP SHAPE THE NEXT ISSUE

What belongs in your toolbox?

Choose a command you want to know better. We start with familiar tools and work toward the less obvious ones.

READER’S CHOICE

What should we cover next?

Vote for a future deep dive, or suggest a command we missed.

One command name, up to 32 characters. Suggestions are reviewed by a person. A new article starts a fresh poll.

Loading poll…