Debian 定时器(timer)是基于 systemd 的,因此它遵循 systemd 的规则。systemd timer 是可以跨月的,只要定时器的配置正确。
要创建一个跨月的定时器,你需要在定时器单元文件中设置 OnCalendar 或 OnUnitActiveSec/OnBootSec 等选项。以下是一个简单的示例:
my-service.service):[Unit]
Description=My custom service
[Service]
ExecStart=/path/to/your/script.sh
my-service.timer):[Unit]
Description=Run my-service monthly
[Timer]
OnCalendar=*-*-* 00:00:00
Persistent=true
[Install]
WantedBy=timers.target
在这个例子中,OnCalendar=*-*-* 00:00:00 表示每月的第一天午夜触发定时器。Persistent=true 表示如果系统在定时器触发时处于关机状态,那么在系统下次启动时会立即触发定时器。
sudo systemctl enable --now my-service.timer
这样,你的定时器就会在每月的第一天午夜触发。你可以根据需要调整 OnCalendar 的值来设置不同的触发时间。更多关于 OnCalendar 的格式和选项,你可以查阅 systemd 的文档:https://www.freedesktop.org/wiki/Software/systemd/man/systemd.timer.html