2018-11-15 shell练习题

假如,当前mysql服务的root密码为123456,写脚本检测mysql服务是否正常(比如:可以正常进入mysql执行show processlist),并检测一下当前的mysql服务是主还是从,如果是从,请判断它的主从服务是否异常,如果是主,则不需要做什么

#!/bin/bash
RTV=0
mysql=/usr/lcoal/mysql/bin/mysql -uroot
$mysql -e "show processlist"  
RTV=$?
if [ $RTV -eq 0 ] 
  then 
     $mysql -e "show status master\G"
	 RTV=$?
    else if [ $RTV -eq 0 ]
	 then
	    echo "It's OK!"
	   else
	     $mysql -e "show slave status\G" >/tmp/2.txt
	      n1= grep "slave_IO" |awk -F ":" 'print {$2}'
		  n2= grep "slave_SQL"|awk -F ":" 'print {$2}'
		  if [ $n1 -eq 0 && $n2 -eq 0 ]
		   then 
		     echo " mysql AB is OK !"
		   else 
		     echo "mysql AB is not OK!"
		   fi
	fi
	
fi

猜你喜欢

转载自blog.csdn.net/a1779078902/article/details/84344256