写监控脚本 不同步时发送邮件
#!/bin/bash
. /etc/init.d/functions
function check(){
rep_file=/tmp/rep$(date +%F).txt
while true
do
rep=(`/application/mysql/bin/mysql -e "show slave status\G"|awk '/Slave_SQL_Running:/{print $2};/Slave_IO_Running:/{print $2};$1~/Seconds_Behind_Master/{print $2}'|xargs`)
if [ "${rep[0]}" != "Yes" ]; then
echo "Slave_IO_Running: NO" >$rep_file
break 1
fi
if [ "${rep[1]}" != "Yes" ]; then
echo "Slave_SQL_Running: NO" >$rep_file
fi
if [ "${rep[2]}" -ne 0 ]; then
echo " Seconds_Behind_Master delay" >$rep_file
break 1
fi
sleep 3
done
}
function main(){
while true
do
check
mail -s "replication false" 861740772@qq.com </tmp/rep$(date +%F).txt