#!/bin/bash
id=`hostname`
datetime=`date +%Y%m%d_%H%M%S`
cmd=/usr/local/mysql/bin/mysql
mysqluser=root
mysqlpasswd=OvM9qIB1QGY06
sock=/data/mysql/mysql.sock
log=/data/mysql/slave.log
${cmd} -u${mysqluser} -p${mysqlpasswd} -S ${sock} -e "show slave status\G" | grep -i "running:" >${log}
Slave_IO_Running=`grep Slave_IO_Running $log| awk ' {print $2}'`
Slave_SQL_Running=`grep Slave_SQL_Running ${log} | awk '{print $2}'`
if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ];then
echo "Slave is Running!"
else
echo "${datetime} ${id} Slave is not running!" >>${log}
fi