Under Liunx, monitor whether the specified program process is online and start it if it is not offline.

Script

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

Write scheduled tasks

crontab -e

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

systemctl reload crond.service

Guess you like

Origin blog.csdn.net/qq_34591972/article/details/131759957