A simple script for detecting whether the mysql master/slave is normal or not bitsCN.com
Script for simple mysql master/slave check
I want to use a simple script to test whether the master and slave databases 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
BitsCN.com