Adding a once off triggering of a systemd timer
I have a systemd timer which runs at 23:00 on Fridays in order to do some batch data processing once a week during low demand times. It is Tuesday, and I would like to test a change I have made, I would like it to start at 23:00 today, so that I can check it tomorrow, rather than having to wait until next Monday.
Is there an easy & build in way to schedule a once-off triggering of a systemd timer? e.g. systemd trigger-timer --timer whatever.timer --at 2021-06-22T23:00
or something? I want it only to start at this time, I don't want to add a new recurring rule. I want it to run as regular every Friday at 23:00 and today at 23:00.
I'm sure I could hack something together with sleep 10hr ; systemctl start whatever.service
or maybe manually edit the /etc/systemd/system/whatever.timer
file, but if there's is a proper way to do "once off" triggerings of a timer, I would prefer to use that.
This is on Ubuntu Linux 20.04 & 18.04, whatever version of systemd that is (245?)
Solution 1:
You could add a
OnCalendar=2021-06-22T23:00
to your timer unit file. Then remove it after you are done. Or if you just want to trigger the service, you could do:
systemd-run --on-calendar=2021-06-22T23:00 systemctl start example.service
Solution 2:
A one-off triggering of a timer is not a timer, and a one-off firing of the service can be achieved with at
or using a cron.
at 23:00 <<<"systemctl start example.service"
would be fairly equivalent to what you're looking for.