[root@master ~]# cat check_master_slave_status.sh
#!/bin/bash
check(){
list=($(mysql -uroot -p123456 -S /tmp/mysql.sock2 -e "show slave status\G;" 2>/dev/null |egrep "Running|Behind" |head -n3|awk -F ':' '{print $2}'))
#echo ${list[@]}
if [ '${list[0]} = "Yes" -a ${list[1]} = "Yes" -a ${list[2]} -lt 120']; then
echo "${list[0]} is ${list[0]}"
echo "${list[1]} is ${list[1]}"
echo "${list[2]} is ${list[2]}"
echo "mysql slave is ok!"
else
#echo ""
mail -s "mysql slave is not ok" hehe@163.com
fi
}
while :
do
check
sleep 3
done