- 系统的timer.target 一定要启动
- 要有个sname.service 的服务存在(sname 是你自己指定的名称)
- 要有个sname.timer 的时间启动服务存在
测试脚本
remove-log.sh
#!/bin/bash
date >> /home/xx/remove-log
echo "run remove " >> /home/xx/remove-log
service文件:remove-log.service --> /etc/systemd/system/
[Unit]
Description= Remove gateway log service
[Service]
ExecStart=/home/xx/remove-log.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
timer文件:remove-log.timer --> /etc/systemd/system/
[Unit]
Description=remove gateway log timer
[Timer]
#start remove-log.timer after bootup 1min, then run remove-log.service every 30s
OnBootSec=1min
OnUnitactiveSec=30s
#every 2:00 on sunday
#OnCalendar=Sun *-*-* 02:00:00
#Persistent=true
#Unit=remove-log.service
[Install]
WantedBy=multi-user.target
验证timer:
systemctl daemon-reload
systemctl enable remove-log.timer
systemctl start remove-log.timer
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。