如何使用 OnCalendar 指示计时器中的小时范围?

如何使用 OnCalendar 指示计时器中的小时范围?

系统219版本

Ubuntu 22.04.2 LTS

[Unit]
Description=Run myscript.service every 5 minutes

[Timer]
OnCalendar= *-*-* 10-23:10/5:00
Persistent=true

[Install]
WantedBy=timers.target

我需要每小时过 10 分钟运行一次服务,直到 23:10。 (10:10、11:10、12:10 ..23:10)。我很难指出时间范围。

我努力了10-23, 10..23甚至粘贴了另一个人的相同日期邮政。还是没有用。

错误

Dec 27 16:48:09 node1 systemd[1]: [/etc/systemd/system/myscript.timer:5] Failed to parse calendar specification, ignoring: *-*-* 10..23:10/5:00
Dec 27 16:48:09 node1 systemd[1]: myscript.timer lacks value setting. Refusing.
Dec 27 16:52:51 node1 systemd[1]: [/etc/systemd/system/myscript.timer:5] Failed to parse calendar specification, ignoring: *-*-*10..23:10/5:00
Dec 27 16:52:51 node1 systemd[1]: myscript.timer lacks value setting. Refusing.
Dec 27 16:55:18 node1 systemd[1]: [/etc/systemd/system/myscript.timer:5] Failed to parse calendar specification, ignoring: *-*-* 9-17:00:00
Dec 27 16:55:18 node1 systemd[1]: myscript.timer lacks value setting. Refusing.
Dec 27 16:56:45 node1 systemd[1]: [/etc/systemd/system/myscript.timer:5] Failed to parse calendar specification, ignoring: *-*-* 9-18:00:00
Dec 27 16:56:45 node1 systemd[1]: myscript.timer lacks value setting. Refusing.
Dec 27 16:57:59 node1 systemd[1]: [/etc/systemd/system/myscript.timer:5] Failed to parse calendar specification, ignoring: *-*-* 10-23:10/5:00
Dec 27 16:57:59 node1 systemd[1]: myscript.timer lacks value setting. Refusing.

答案1

x..y仅在以下版本中添加了对时间范围语法的支持系统版本 231

CHANGES WITH 231:

        * Calendar time specifications in .timer units now understand a ".."
          syntax for time ranges. Example: "4..7:10" may now be used for
          defining a timer that is triggered at 4:10am, 5:10am, 6:10am and
          7:10am every day.

对于旧版本,您需要指定多个OnCalendar=设置,每小时一个,或者更改脚本本身以检查当前时间,如果超出时间间隔则立即退出。

相关内容