#!/bin/bash #check MySQL_Slave Status #crontab time 09:00 MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk ‘{print $4}‘|awk -F: ‘{print $2}‘` MYSQLIP=`ifconfig|awk ‘NR==2{print $2}‘|awk -F: ‘{print $2}‘` STATUS=$(mysql -hxxx -uxxx -pxxx -S /tmp/mysql.sock -e "show slave status\G" | grep -i "running") 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 echo $MYSQLIP mysql is down" | 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 "Slave is not running!" | mail -s "warn! $DATA $MYSQLIP MySQL Slave is not running" [email protected] fi
时间: 2024-10-15 05:31:51