Short answer
Make two files in /etc/systemd/system/: myjob.service (Type=oneshot, ExecStart= your script) and myjob.timer (OnCalendar=*-*-* 03:00:00, Persistent=true, WantedBy=timers.target). Check the schedule with systemd-analyze calendar, then run sudo systemctl enable --now myjob.timer. Enable the timer, not the service.
Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed
Step 1: The job, as a service
The example job deletes files in /var/tmp older than 7 days and says how many:
$ sudo tee /usr/local/bin/cleanup-tmp > /dev/null <<'EOF'#!/bin/shn=$(find /var/tmp -name '*.tmp' -mtime +7 -print -delete | wc -l)echo "cleanup: removed $n old files"EOF$ sudo chmod +x /usr/local/bin/cleanup-tmpA timer starts a service, so the job needs a service file. Type=oneshot means it runs, finishes, and is done; it has no [Install] section because the timer, not the boot, starts it:
$ sudo tee /etc/systemd/system/cleanup.service <<'EOF'[Unit]Description=Remove old temp files [Service]Type=oneshotExecStart=/usr/local/bin/cleanup-tmpEOFRun it once by hand before scheduling it, and read what it printed:
$ sudo systemctl daemon-reload && sudo systemctl start cleanup.service$ sudo journalctl -u cleanup -o cat --no-pagerStarting cleanup.service - Remove old temp files...cleanup: removed 3 old filescleanup.service: Deactivated successfully.Finished cleanup.service - Remove old temp files.The test server had three old files and one new one; the job removed the three.
Step 2: The timer
Same name as the service, ending in .timer, so it starts cleanup.service:
$ sudo tee /etc/systemd/system/cleanup.timer <<'EOF'[Unit]Description=Remove old temp files every night [Timer]OnCalendar=*-*-* 03:00:00Persistent=true [Install]WantedBy=timers.targetEOFOnCalendar=*-*-* 03:00:00: every day at 03:00 (year-month-day hour:minute:second;*is any). The cron line0 3 * * *.Persistent=true: if the server was off at 03:00, run once when it is back (proved below).WantedBy=timers.target: whatenablehooks the timer to, so it is armed at every boot.
Check an expression before you trust it. systemd-analyze calendar shows how systemd reads it and when it would run next:
$ systemd-analyze calendar "*-*-* 03:00:00"Normalized form: *-*-* 03:00:00 Next elapse: Fri 2026-11-20 03:00:00 UTC From now: 4h 6min leftWhich time zone does OnCalendar use?
The server’s own time zone. A cloud server usually runs on UTC:
$ timedatectl | grep "Time zone" Time zone: Etc/UTC (UTC, +0000)So 03:00 means 03:00 UTC. To schedule in another zone without changing the server’s, add it after the time:
$ systemd-analyze calendar "*-*-* 03:00:00 Europe/Berlin"Normalized form: *-*-* 03:00:00 Europe/Berlin Next elapse: Fri 2026-11-20 02:00:00 UTC From now: 3h 6min left03:00 in Berlin is 02:00 UTC in November, and systemd works that out itself.
If you enable the service: “The unit files have no installation config”
$ sudo systemctl enable cleanup.serviceThe unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,Also=, or Alias= settings in the [Install] section, and DefaultInstance= fortemplate units). This means they are not meant to be enabled or disabled using systemctl. Possible reasons for having these kinds of units are:• A unit may be statically enabled by being symlinked from another unit's .wants/, .requires/, or .upholds/ directory.• A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it.• A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...).• In case of template units, the unit is meant to be enabled with some instance name specified.Nothing was enabled. The service has no [Install] section on purpose: the timer starts it (“activation … timer” in the list). This message is harmless; enable the timer instead.
Step 3: Enable the timer
$ sudo systemctl enable --now cleanup.timerCreated symlink '/etc/systemd/system/timers.target.wants/cleanup.timer' → '/etc/systemd/system/cleanup.timer'.$ systemctl list-timers cleanup.timer --no-pagerNEXT LEFT LAST PASSED UNIT ACTIVATESFri 2026-11-20 03:00:00 UTC 4h 6min - - cleanup.timer cleanup.service 1 timers listed.Pass --all to see loaded but inactive timers, too.NEXT is the next run, LEFT the time until it, and - under LAST means it has not run yet. systemctl list-timers without a name lists every timer on the server.
Step 4: Check it after a reboot
$ sudo reboot$ systemctl list-timers cleanup.timer --no-pagerNEXT LEFT LAST PASSED UNIT ACTIVATESFri 2026-11-20 03:00:00 UTC 4h 6min Thu 2026-11-19 22:53:10 UTC - cleanup.timer cleanup.service 1 timers listed.Pass --all to see loaded but inactive timers, too.The timer is armed again for 03:00. LAST now shows a time, but the job did not run: with Persistent=true systemd keeps a stamp file in /var/lib/systemd/timers/, writes the current time into it when the timer first starts, and reads it back at boot. A separate test confirmed cleanup.service had no new journal lines after the reboot.
What Persistent=true does with missed runs
To see it in minutes rather than days, a second timer ran every minute, was stopped for two and a half minutes (two runs missed) and started again:
$ sudo tee /etc/systemd/system/tick.service > /dev/null <<'EOF'[Service]Type=oneshotExecStart=/bin/echo tickEOF$ sudo tee /etc/systemd/system/tick.timer > /dev/null <<'EOF'[Timer]OnCalendar=minutelyPersistent=true [Install]WantedBy=timers.targetEOF$ sudo systemctl daemon-reload && sudo systemctl enable --now tick.timer$ sudo systemctl stop tick.timer$ sudo systemctl start tick.timer$ sudo journalctl -u tick -o short-iso --no-pager | grep tick$2026-11-19T22:54:02+00:00 web-server echo[2736]: tick2026-11-19T22:56:35+00:00 web-server echo[3470]: tickOne run before the stop, and ONE run the moment the timer was started again, not one for each missed minute. A server that was off for a week runs a daily job once when it comes back, not seven times. (The test removed the tick timer afterwards.)
Remove the timer
$ sudo systemctl disable --now cleanup.timerRemoved '/etc/systemd/system/timers.target.wants/cleanup.timer'.$ sudo rm /etc/systemd/system/cleanup.timer /etc/systemd/system/cleanup.service /usr/local/bin/cleanup-tmp && sudo systemctl daemon-reload$ systemctl list-timers --all --no-pager | grep -c cleanup0The configuration files, ready to copy
The two files as they were on the test server after the reboot, with the timer armed.
[Unit]Description=Remove old temp files [Service]Type=oneshotExecStart=/usr/local/bin/cleanup-tmpRead back from the test server (Ubuntu 26.04) on 2026-11-19, after the steps had worked. Placeholders such as [password]: type your own value in the box above the file to fill them in, or replace them yourself.
[Unit]Description=Remove old temp files every night [Timer]OnCalendar=*-*-* 03:00:00Persistent=true [Install]WantedBy=timers.targetRead back from the test server (Ubuntu 26.04) on 2026-11-19, after the steps had worked. Placeholders such as [password]: type your own value in the box above the file to fill them in, or replace them yourself.
Troubleshooting
- “The unit files have no installation config”: you enabled the
.service; enable the.timer. Details. - It runs an hour early or late: OnCalendar uses the server’s time zone (often UTC). Add the zone after the time. Details.
- The job never seems to run: check NEXT and LAST in
systemctl list-timers, thenjournalctl -uthe service. Details. - LAST shows a time but the job did not run: that is the stamp of a Persistent timer, not a run. Details.
What these steps changed on the server
Both runs recorded the server before the first step and after the reboot (see the Tested on box below): the service file, the timer file, and the timer’s link in timers.target.wants. Nothing was installed.
Ubuntu 26.04 vs 24.04
The same check ran on a fresh 26.04 server and on a fresh 24.04 server, each with its own run log. Every step behaved the same, including the single catch-up run; only one output differed in form:
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-43-generic | Ubuntu 24.04.5 LTS6.8.0-147-generic |
| systemd | 259.9-0ubuntu0.1 | 255.4-1ubuntu8.18 |
| The “Created symlink” / “Removed” lines | paths in single quotes | paths without quotes (“Removed” with double quotes) |
| Proof | Run log, 18 checks passed | Run log, 18 checks passed |
