shell 检测mysql 主从状态

在从上执行:

[[email protected] ~]# 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]!="NULL"];thenecho{list[2]} != "NULL" ]; then echo '{list[0]}’ "is list[0]"echo{list[0]}" echo '{list[1]}’ "is list[1]"echo{list[1]}" echo '{list[2]}’ “is ${list[2]}”
echo “mysql slave is ok!”
else
#echo “”
mail -s “mysql slave is not ok” [email protected]
fi
}
while :
do
check
sleep 3
done
shell 检测mysql 主从状态yum -y install mailx 安装mail客户端

vim /etc/mail.rc
set [email protected] #对方收到邮件时显示的发件人
set smtp=smtp.qq.com
set [email protected] #发邮件的用户名
set smtp-auth-password=jponzubigyxxbiaj #这是授权码!不是密码!
set smtp-auth=login
shell 检测mysql 主从状态
mail -s “你的邮件主题” [email protected] < /tmp/result.txt (邮件内容)

echo “hehe”|mail -s ‘主题’ [email protected]
shell 检测mysql 主从状态