Linux systemed timer 定时任务

创建服务

nano /etc/systemd/system/myshsh.service

1
2
3
4
5
6
7
[Unit]
Description=Add a short description

[Service]
User=root
ExecStart=your command
KillMode=process

创建定时器

1
nano /etc/systemd/system/mysh.timer
1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Add a short description

[Timer]
OnBootSec=5min
OnUnitActiveSec=30min
Unit=mysh.service

[Install]
WantedBy=timers.target

运行并设置开机自动运行

systemctl enable --now mysh.timer

重新载入

systemctl daemon-reload

停止计时器并关闭开机自动运行

systemctl disable --now mysh.timer
systemctl daemon-reload

文章作者: Barry
文章链接: http://blog.purplelin.com/2021/08/18/linuxsystemedtimer/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Barry