Linux利用cron定时+脚本配置定时守护
#
#!/bin/sh
# 守护脚本,通过 grep 命令检查进程是否存在然后重新启动进程
# 可以配置多个进程
# */3 * * * * /home/test/Tools/Develop/work.sh>>//root/cheack.log
# 根据进程名判断进程是否消失(行数为0),红字为查询进程关键字,必须唯一
if test `ps -ef | grep ‘homeassistant’ |grep -v vi |grep -v grep| wc -l` -eq 0
then
#记录发生时间 ,记录丢失进程名
echo `date`
echo ‘homeassistant is missing.And the programme is restarting…!’
#重新启动程序,自己配置
systemctl restart homeassistant
fi
# 根据进程名判断进程是否消失(行数为0),programme name为查询进程关键字,必须唯一
if test `ps -ef | grep ‘syncthing’ |grep -v vi |grep -v grep| wc -l` -eq 0
then
#记录发生时间 ,记录丢失进程名
echo `date`
echo ‘syncthing is missing.And the programme is restarting…!’
#重新启动程序,自己配置
systemctl restart syncthing
fi