Liunx下监控指定程序进程是否在线,不下线启起来

编写脚本

vim test.sh

#!/bin/bash

while true
flag=`ps -ef |grep "zabbix" |grep -v "grep" |wc -l`			#zabbix 代表要监控的进程名称
do
        if [[ $flag -eq 0 ]]
        then
               echo ">>>>no zabbix,run it"
        cd /etc/
			./zabbix-agentd start
         echo $(date "+%Y%m%d-%H%M%S") - "zabbix restart" >> running.log
        else
        echo ">>>>zabbix is running"
                echo "zabbix is running..." >> /dev/null
        fi
        sleep 10s
done

编写定时任务

crontab -e

*/10 * * * * /etc/auto_start_zabbix-agentd.sh

systemctl reload crond.service

猜你喜欢

转载自blog.csdn.net/qq_34591972/article/details/131759957
今日推荐