mysql同步检测的脚本

#!/bin/bash
mysql_path=/usr/local/mysql/bin/mysql
user="root"
password="123456"
email="[email protected]"
date=`(date +%y-%m-%d--%H:%M:%S)`
ip=$(/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{print $2;}' | awk -F':' '{print $2;}' | head -1)
Slave_IO_Running=$($mysql_path -u$user -p$password -e 'show slave status\G' | grep "Slave_IO_Running" | awk '{print $2}')
Slave_SQL_Running=$($mysql_path -u$user -p$password -e 'show slave status\G' | grep "Slave_SQL_Running" | awk '{print $2}')
if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]
then
  echo "Slave is running!"
else
  echo "#######  $date  #########">> /var/log/mysql_slave.log
  echo "Slave is not running!" >> /var/log/mysql_slave.log
  /bin/mail -s {$ip}_replicate_error $email
fi

你可能感兴趣的:(数据库,mysql,脚本,检测,休闲)