#!/bin/bash #check MySQL_Slave Status #crontab time 00:10 MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ ‘{print $4}‘` MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ ‘{print $4}‘` STATUS=$(/usr/bin/mysql -S /var/lib/mysql/mysql.sock -e "show slave status\\G" | grep -i "running") STATUS=$(/usr/bin/mysql -uroot -pPASSWD -e "show slave status\\G"|grep "Running" |awk ‘{print $2}‘)) IO_env=`echo $STATUS | grep IO | awk ‘ {print $2}‘` SQL_env=`echo $STATUS | grep SQL | awk ‘{print $2}‘` DATA=`date +"%y-%m-%d %H:%M:%S"` if [ "$MYSQLPORT" == "3306" ] then echo "mysql is running" else mail -s "warn!server: $MYSQLIP mysql is down" [email protected] fi if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ] then echo "Slave is running!" else echo "####### $DATA #########">> /data/data/check_mysql_slave.log echo "Slave is not running!" >> /data/data/check_mysql_slave.log echo "Slave is not running!" | mail -s "warn! $MYSQLIP MySQL Slave is not running" [email protected] fi #设置cron每十分钟运行一次 #*/10 * * * * root /bin/sh /root/mysql_slave.sh
时间: 2024-12-14 14:56:00