1. 创建shell脚本 test.sh ,并将脚本放到指定目录(建议 /root/.config 目录)
#!/bin/bash
while [ 2 -gt 1 ]
do
echo 'ok ...' >> /root/aaa.txt
sleep 2s
done
2. 创建 mytest.service
[Unit]
Description=my first service
[Service]
ExecStart=/bin/bash /root/.config/test.sh
[Install]
WantedBy=multi-user.target
3. 移动 mytest.service 到 /etc/systemd/system/ 目录下
4. 重新加载
systemctl daemon-reload
5. 设置开机启动
systemctl enable mytest.service
systemctl start mytest.service
6. 设置时间间隔检测脚本运行可以在 test.sh 中写循环脚本
本文介绍了如何创建shell脚本test.sh并将其放置在指定目录,随后构建mytest.service并配置为systemd服务,实现定时启动。通过一步步操作,读者将学会如何管理服务生命周期和设置时间间隔检测。
3223

被折叠的 条评论
为什么被折叠?



