#!/usr/bin/env bash
base_dir="/home/mysql/mysql-5.7.20-linux-glibc2.12-x86_64"
mysql_host="10.1.1.1"
mysql_user="bkp_user"
mysql_psw="password"
mysql_port="3306"
function get_v()
{
if test -f /tmp/mysql_slave.txt; then
# for ((i=1;i<6;i++)); do
# args$i=`awk -v i=$1 'NR==i {print $NF}' /tmp/mysql_slave.txt`
case $1 in
1)
args1=`awk 'NR==1 {print $NF}' /tmp/mysql_slave.txt`
;;
2)
args2=`awk 'NR==2 {print $NF}' /tmp/mysql_slave.txt`
;;
3)
args3=`awk 'NR==3 {print $NF}' /tmp/mysql_slave.txt`
;;
4)
args4=`awk 'NR==4 {print $NF}' /tmp/mysql_slave.txt`
;;
5)
args5=`awk 'NR==5 {print $NF}' /tmp/mysql_slave.txt`
;;
*)
echo "usag: sh $0 1~5"
esac
# done
else
echo "something errors!"
exit 0
fi
}
$base_dir/bin/mysql -h$mysql_host -u$mysql_user -p$mysql_psw -Pmysql_port -e 'show slave status\G;' |egrep 'Read_Master_Log_Pos|Exec_Master_Log_Pos|Master_Log_File|Relay_Master_Log_File|Seconds_Behind_Master' >/tmp/mysql_slave.txt
for ((i=1;i<6;i++)); do
get_v $i
done
if [ $args1 == $args3 -a $args2 == $args4 ]; then
echo "slave status ok!"
else
printf "seconds behind master: $args5\n"
printf "+%13s+%11s+\n" ------------- -----------
printf "|%13s|%11s|\n+-------------+-----------+\n" $args1 $args2
printf "|%13s|%11s|\n+-------------+-----------+\n" $args3 $args4
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9522838/viewspace-2285008/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9522838/viewspace-2285008/