What it does
systemd-run COMMAND starts the command as a new service unit (like run-u123.service). It runs in the background, is managed by systemd, and its output goes to the journal. No unit file is needed.
With timer options (--on-calendar, --on-active) it works like at with logging. With -p you set unit properties, for example memory or CPU limits. --scope runs the command in the foreground in its own cgroup.
How to write it
systemd-run [OPTION]... COMMAND [ARGUMENT]...Options 35
Most used
Unit
Run as / environment
Input and output
Timers and triggers
Other
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Run a command as a background service
systemd-run --unit=reindex /usr/local/bin/reindex.sh Running as unit: reindex.serviceSurvives logout; follow it with
journalctl -u reindex -f.2Run once in 30 minutes
systemd-run --on-active=30m /usr/bin/systemctl restart httpdLike at, but logged in the journal.
3Run every day at 02:00 (until reboot)
systemd-run --on-calendar='*-*-* 02:00' --unit=nightly /usr/local/bin/report.shA quick timer for a test; write unit files for permanent ones.
4Limit memory and CPU of a command
systemd-run --scope -p MemoryMax=500M -p CPUQuota=50% tar -czf /tmp/big.tgz /dataThe command cannot take the whole server.
5Run as another user
systemd-run --uid=lisa --pty --wait /usr/bin/whoami lisaClean environment, like a service.
6See the result of a command
systemd-run --wait --pipe /usr/bin/falseShows the exit code and run time.
7Your own long task without root
systemd-run --user --unit=longtask ./long-task.sh journalctl --user -u longtask -fBetter than nohup.
8Test hardening settings on a command (DevSecOps)
systemd-run --pty -p ProtectSystem=strict -p PrivateTmp=yes /usr/bin/bashTry what a service could do with these settings.
9List and stop transient units
They disappear after they end.
10Check running timers made by systemd-run
systemctl list-timersTransient timers show up like normal ones.
Nothing matches this filter.
Exit codes
0 :: Done (with --wait: the exit status of the command). 1 :: Error.