brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd-run --on-active runs a command once, a bit later

Systemd
~/tips/tip-systemd-run-on-active-later

sudo systemd-run --on-active=30min /usr/local/bin/backup.sh

Schedules a single command for later without at or a unit file.

The at command is missing on plenty of minimal servers, and I don’t want to install a package just to run one thing in half an hour. systemd can already do it.

With a timer option, systemd-run creates a transient timer plus a transient service for your command. You don’t write any unit file, and both units go away once the job is done.

sudo systemd-run --on-active=30min /usr/local/bin/backup.sh

It replies with Running as unit: run-…timer and Will run service as unit: run-…service. Those names are how you find the job again. systemctl list-timers shows it with the time left, and after it has fired, journalctl -u with the service name shows everything the script printed. That beats a mail from at that ends up nowhere.

For a clock time, use --on-calendar, which takes the same syntax as OnCalendar= in a timer file. I’d add --unit= so the job gets a name you can remember instead of a random one:

sudo systemd-run --unit=report-once --on-calendar="2026-12-01 03:00" /usr/local/bin/report.sh

Now journalctl -u report-once.service finds the output later. Changed your mind? sudo systemctl stop report-once.timer cancels it.

The catch is the word transient. These units live under /run/systemd/transient, and /run is gone after a reboot, so a job scheduled for tomorrow disappears if the machine restarts tonight. The command also runs in a clean service environment, without your shell’s PATH or variables, so use full paths. For anything that has to happen every day, my advice is still a real timer unit on disk.

Further reading: systemd-run(1) manual page, systemd.timer(5) manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link