#!/bin/bash

ip=$1

/bin/ping $1 -c1 -w1 &> /dev/null

if [ $? -eq 0 ]; then

/usr/bin/mysql -u mysqlshell -p123 -h $1 -e "show slave status \G" &> ./status.txt

if [ $? -eq 0 ];then

# IO=`/usr/bin/mysql -u mysqlshell -p123 -h $1 -e "show slave status \G"| /bin/awk -F ":" 'NR==12{print $2}'`

# SQL=`/usr/bin/mysql -u mysqlshell -p123 -h $1 -e "show slave status \G"| /bin/awk -F ":" 'NR==13{print $2}'`

IO=`cat ./status.txt | /bin/awk -F ":" 'NR==12{print $2}'`

SQL=`cat ./status.txt | /bin/awk -F ":" 'NR==13{print $2}'`

if  [ $IO =  Yes ] && [ $SQL = Yes ]; then

echo "master and slave is synchronization!!!"

exit 0

else 

echo "master and slave is Not synchronized!!!"

exit 1

fi

else

echo "Can't connect to MySQL server on '$1'!!!"

exit 2

fi

else

echo "slave host Unreachable!!!"

exit 3

fi