一、需求背景
系统中存在YLMS.service该服务需要定时执行重启,否则运行会出错。
二、具体实现
编写shell脚本:
while true; do
current_time=$(date '+%Y-%m-%d %H:%M:%S')
echo "$current_time Restarting YLMS service"
systemctl restart YLMS.service
if [ $? -eq 0 ]; then
echo "$current_time YLMS service restarted successfully"
else
echo "$current_time Failed to restart YLMS service"
fi
sleep 12h
done
加入计划任务中:每天凌晨三点执行一次
[
0 3 * * * /temp/sh/YLMS.sh