Script for simple mysql master/slave check

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.