You're looking for systemd-run
, specifically one of the timer-related options: --on-active=, --on-boot=, --on-startup=, --on-unit-active=, --on-unit-inactive=
and --on-calendar=
.
Using a monotonic timer:
systemd-run --user --on-startup=0s --on-unit-inactive=5s --timer-property=AccuracySec=100ms sh -c 'notify-send "invoked" "$(date)"'
Using a calendar (wall-clock) timer:
systemd-run --user --on-calendar='*:*:0/5' --timer-property=AccuracySec=100ms sh -c 'notify-send "invoked" "$(date)"'
Note that the default timer accuracy is 1 minute, which is too coarse for timer intervals as short as 5 seconds.
Other useful arguments to systemd-run
you will likely want to use include --unit
/-u
(for naming the unit) and --description
(for providing a description that is shown by systemd, in the journal, etc. instead of the triggered command).
The transient systemd units behave just like regular ones. Once they are no longer referenced anywhere, they are garbage collected as described here.
while true; do notify-send ...; sleep 5; done
?watch
:watch -n5 my_command