大网数据广告活动
服务器运维问答

Adding a once off triggering of a systemd timer

· 52CE 我爱测

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 …

问题原文

原帖链接 · Amandasaurus · CC BY-SA 4.0

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

已采纳解答

原帖链接 · Thayne · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-06-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。