liunx服务器监控脚本(监控nginx,php-fpm,mysql)

码农专业户 2017-05-19

#!/bin/bash
ip=$(ifconfig eth0 | awk -F'addr:|Bcast' '/Bcast/{print $2}')
num=`ps aux | grep php-fpm | grep -v grep | wc -l`
if [ $num -eq 0 ];then
        php alarm.php  "php-fpm is not running on $ip"
        /etc/init.d/php-fpm start
fi

num=`ps aux | grep nginx | grep -v grep | wc -l`
if [ $num -eq 0 ];then
        php alarm.php  "nginx is not running on $ip"
        /etc/init.d/nginx start
fi

cmd=`/usr/local/mysql/bin/mysqladmin -h127.0.0.1 -uroot -proot ping`
echo "$cmd" | grep -q "alive"
if [ $? -ne 0 ];then
        php alarm.php  "mysql is not running on $ip"
        /etc/init.d/mysql start
fi

相关推荐