shell監控mysql主從同步

#!/bin/shmysql

MYSQLPORT=`netstat -na|grep"LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`sql

MYSQLIP=`ifconfig eth0|grep"inet addr" | awk -F[:" "]+ '{print $4}'`ide

STATUS=$(/usr/local/mysql/bin/mysql-e "show slave status\G" | grep -i "running")rest

IO_env=`echo $STATUS | grep IO |awk  ' {print $2}'`it

SQL_env=`echo $STATUS | grep SQL| awk  '{print $2}'`io

 

function checkMysqlStatus(){mysqli

    if [ "$MYSQLPORT" =="3306" ]function

    thenclass

        /usr/local/mysql/bin/mysql  --connect_timeout=5 -e "showdatabases;" &>/dev/null 2>&1awk

        if [ $? -ne 0 ]

        then

            echo "Server: $MYSQLIP mysqlis down, please try to restart mysql by manual!" > /var/log/mysqlerr

        else

            echo "mysql isrunning..."

        fi

    else

        echo "WARN!Server: $MYSQLIP mysqlis down."

    fi

}

 

checkMysqlStatus

 

if [ "$IO_env" ="Yes" -a "$SQL_env" = "Yes" ]

then

 echo "MySQL Slave is running!"

else

 echo "####### $DATA #########">>/data/mysql_slave_status.log

 echo "MySQL Slave is not running!" >>    /data//mysql_slave_status.log

 echo "MySQL Slave is not running!"

fi

相關文章
相關標籤/搜索