The script that checks whether mysql master and slave are normal is learning myslq master and slave, and wants to use a simple script to test whether the master and slave are normal.
01 #! /Bin/bash0203while getopts "h: u: p: P:" arg # The colon following the option indicates that the parameter 04do05 case $ arg in06 h is required for this option) 07 HOST = $ OPTARG # The parameter exists in $ OPTARG 08; 09 u) 10 USER = $ OPTARG11; 12 p) 13 PASSWD = $ OPTARG14; 15 P) 16 PORT = $ OPTARG17; 18 ?) # When there are unrecognized options, What Is arg? 19 echo "unkonw argument" 20 exit 1 ;; 21 esac22done232425 # obtain the id address 26ip = 'ifconfig eth0 | sed-n 2p | awk '{print $2}' | awk-F: '{print $2}' '27array = ($ (mysql-h $ HOST-u $ USER-p $ PASSWD-P $ PORT-e "show slave status \ G" | grep "Running" | awk '{print $2 }')) 28if ["$ {array [0]}" = "Yes"] | ["$ {array [1]}" = "Yes"] 29 then30 echo "slave is OK "31 else32 # Send email 33 #/home/shell/sendEmail-f XXX @ XXX-t XXX @ XXX-s smtp. XXX-u "mysql Master/slave replication error"-xu user-xp passwd-m "$ {ip}: slave is error" 34 echo "mysql Master/slave replication error" 35fi