shell脚本:nagios监控mysql同步

#!/bin/bash
#For nagios.
#sndapk(20140106)
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
IFS=' 
'
export PATH IFS
MySQLPORT="3306"
MYSQLIP="127.0.0.1"
MYSQLUSER="slavemonitor"
MYSQLPW="123456"
MYSQL="/usr/local/mysql-5.0.92/bin/mysql"
netstat -ntl | grep -q "$MYSQLPORT"
if [ $? -ne 0 ];then
    echo "NO MYSQLD PROCESS!"
    exit 2
fi
STATUS=$($MYSQL -h$MYSQLIP -u$MYSQLUSER -p$MYSQLPW -e "show slave status\G" | egrep -i 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master')
IO_status=`echo $STATUS | awk '/IO/{print $2}'`
SQL_status=`echo $STATUS | awk '/SQL/{print $4}'`
SEC_status=`echo $STATUS | awk '/Seconds/{print $6}'`
if [ "$IO_status" == "Yes" ];then
    if [ "$SQL_status" == "Yes" ];then
        if [ "$SEC_status" -eq 0 ];then
            echo "Mysql copy OK!"
            exit 0
        else
            echo "Seconds_behind_master:$SEC_status"
            exit 1
        fi
    else
        echo "Slave_SQL thread is not running!"
        exit 2
    fi
else
    echo "Slave_IO thread is not running!"
    exit 2
fi

注:

发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及成都餐厅设计等,在网站建设公司成都全网营销、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。

1、脚本中监控用的mysql用户(slavemonitor)仅需赋予SUPER权限。


当前标题:shell脚本:nagios监控mysql同步
网站URL:http://myzitong.com/article/pcides.html