#!/bin/bash
USER="root"
PASSWORD="root"
MYSQL="/usr/mysql/mysql-5.6.10/client/mysql"
HOST="10.198.18.18"
thread_status=$($MYSQL -u"$USER" -p"$PASSWORD" -h"$HOST" -e 'show slave status\G' | grep -i yes | wc -l)
status=($($MYSQL -u"$USER" -p"$PASSWORD" -h"$HOST" -e 'show slave status\G' | egrep -i "Master_Log_File|Relay_Master_Log_File|Read_Master_Log_Pos|Exec_Master_Log_Pos|Seconds_Behind_Master" | awk -F':' '{print $2}'))
if [[ $thread_status != 2 ]]; then
#echo "the replication is fault, at $(date)" > monitor_err.log
echo 1
exit
fi
if [[ ${status[4]} > '300' ]]; then
#echo "the lag is too long, at $(date)" > monitor_err.log
echo 2
exit
fi
if [[ ${status[0]} == ${status[2]} ]] && [[ ${status[1]} == ${status[3]} ]]; then
#echo "the replication is normal"
echo 0
exit
else
#echo "the replication is fault,at $(date)" > monitor_err.log
echo 3
exit
fi
原文地址:http://blog.51cto.com/ultrasql/2149249