| 用途 | 用 systemd 定时器替代 cron |
|---|---|
| 语法 | unit.timer + unit.service(OnCalendar/OnBootSec) |
| 所属 | systemd |
timer 单元示例
timer 单元示例
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily backup
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=10m
[Install]
WantedBy=timers.target配套 service
配套 service
# /etc/systemd/system/backup.service
[Unit]
Description=Run backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh启用与查看
启用与查看
systemctl daemon-reload
systemctl enable --now backup.timer
systemctl list-timers --all
systemctl status backup.timerPersistent=true 让错过的触发(关机期间)在开机后补跑一次,服务器巡检类任务建议开启。