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


