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

#!/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

猜你喜欢

转载自bestscw.iteye.com/blog/2375156
今日推荐