Score:1

Adding a once off triggering of a systemd timer

bg flag

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?)

Score:3
in flag

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
Score:2
gu flag

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.

Ginnungagap avatar
gu flag
I understand the need for testing in as similar a way as the real timer. This is the best I can come up with but I'm curious if anyone knows of a better way.
Michael Hampton avatar
cz flag
`at` is the way.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.