shell监控进程是否存在(进程数量),循环、crontab任务

2022-04-14  本文已影响0人  无味wy

监控服务进程是否存在

#!/bin/bash

while true 
do
    phpfpm_procnum=`ps -ef|grep "php-fpm"|grep -v grep|wc -l`
    nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
    mysql_procnum=`ps -ef|grep "mysqld"|grep -v grep|wc -l`
    redis_procnum=`ps -ef|grep "redis"|grep -v grep|wc -l`
    
    if [ $phpfpm_procnum -eq 0 ]
    then
        echo "start php-fpm..."
        /etc/init.d/php-fpm start >> /var/log/listen_service_start.log 2>&1
    elif [ $nginx_procnum -eq 0 ]
    then 
        echo "start nginx..."
        /usr/local/nginx/sbin/nginx >> /var/log/listen_service_start.log 2>&1
    elif [ $mysql_procnum -eq 0 ]
    then 
        echo "start mysql..."
        systemctl start mysqld >> /var/log/listen_service_start.log 2>&1
    elif [ $redis_procnum -eq 0 ]
    then 
        echo "start redis..."
        systemctl start redis >> /var/log/listen_service_start.log 2>&1
    else 
        #echo "no cmd"
    fi
    sleep 30 #每30秒检查一轮
done
#!/bin/bash

    index=`ps -ef|grep "voiceTask.sh"|grep -v grep|wc -l`
    
    if [ $index -lt 3 ]
    then
        echo "start voiceTask.sh..."
        sh -x /home/work/webroot/Zn_tp/app/report/task/voiceTask.sh & >> /dev/null 2>&1
    else 
    echo "${index}`date`" >> /dev/null 2>&1
    fi
上一篇下一篇

猜你喜欢

热点阅读