#!/bin/bash
#written by zhanghy
##### Setting some variables #####
#192.168.10.20-----/tmp/mysql2.sock
#192.168.10.100----/tmp/mysql3.sock
#192.168.10.105----/tmp/mysql4.sock
mycommand=/usr/local/mysql/bin/mysql
server="192.168.10.20 192.168.10.100 192.168.10.105"
socket="/tmp/mysql2.sock /tmp/mysql3.sock /tmp/mysql4.sock"
ruser2=root
myuser1=root
##### SLAVES: Check replication #####
#check replication status
for i in $socket
do
tmpmysql1=$($mycommand -u $myuser1 --socket=$i -e "show slave status\G" | \
awk 'BEGIN {
tel = 0
}
/Slave_IO_Running: Yes/ { tel++ }
/Slave_SQL_Running: Yes/ { tel++ }
END {
if ( tel == 2 ) {
print "Yes"
} else {
print "No"
}
}'
)
done
#define display function
OutMasterLogbinPosition()
{
echo -e "\n"
echo "$replication"
echo "Master log_bin Position:$tmp2mysql1"
}
OutSlaveRMLAndSBM()
{
echo -e "\n"
echo "Slave Read_Master_Log_Pos($n):$tmp2mysql2"
echo "Seconds_Behind_Master:$tmp2mysql3"
}
OutErrorInfo()
{
echo "Last_Errno($n):$tmp2mysql2"
echo "Last_Error($n):$tmp2mysql3"
echo -e "\n"
}
#get mysql master server logbin position
GetMasterServerLogbinPosition()
{
for hostname in $server
do
replication="REPL OK For $hostname - Replicationrocess is fine"
tmp2mysql1=$($mycommand -u $myuser1 -h "$hostname" -e "show master status\G" | \
awk '/Position/ {print $2}')
OutMasterLogbinPosition
done
}
#get replication slave status where slave is ok
#you can get more information by set variables
GetSlaveServerStatusInfo()
{
GetMasterServerLogbinPosition
for n in $socket
do
tmp2mysql2=$(echo 'show slave status\G' |$mycommand -u $myuser1 --socket=$n | \
awk '/Read_Master_Log_Pos/ {print $2}')
tmp2mysql3=$(echo 'show slave status\G' |$mycommand -u $myuser1 --socket=$n | \
awk '/Seconds_Behind_Master/ {print $2}')
OutSlaveRMLAndSBM
done
}
#get slave error information when slave is error
#you can get more information by set variables
GetSlaveServerErrorStatusInfo()
{
GetMasterServerLogbinPosition
for n in $socket
do
tmp2mysql2=$(echo 'show slave status\G' |$mycommand -u $myuser1 --socket=$n | \
awk '/Last_Errno/ {print $2}')
tmp2mysql3=$(echo 'show slave status\G' |$mycommand -u $myuser1 --socket=$n | \
awk '/Last_Error/ {print $2}')
OutErrorInfo
done
}
# Here you generate the part of the output
if [ $tmpmysql1 = 'Yes' ]
then
GetSlaveServerStatusInfo
else
GetSlaveServerErrorStatusInfo
fi
##### END OF SCRIPT #####
阅读(1706) | 评论(1) | 转发(0) |