####### The script application in the production environment is based on the use of mysql Master/Slave ####### vimysqlm-s.sh #! /Bin/baship = 'ifconfigeth0 | sed-n2p | awk & #39; {print $2} & #39; | awk-F: & #39; {print $2} & #39; 'port = 'netstat-anl | grep3306 | sed-n
####### This script is used in the production environment on the basis of mysql Master/Slave ########
Vi mysqlm-s.sh
#! /Bin/bash
Ip = 'ifconfig eth0 | sed-n 2p | awk '{print $2}' | awk-F: '{print $2 }''
Port = 'netstat-anl | grep 3306 | sed-n '1p' | awk' {print $4} '| awk-F:' {print $2 }''
Array = ($ (mysql-uUSER-pPASSWD-e "show slave status \ G" | grep "Running" | awk '{print $2 }'))
If ["$ port" == "3306"]
Then
If ["$ {array [0]}" = "Yes"] | ["$ {array [1]}" = "Yes"]
Then
Echo "slave is OK"
Else
/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"
Fi
Else
/Home/shell/sendEmail-f XXX @ XXX-t XXX @ XXX-s smtp. XXX-u "mysql stops running"-xu user-xp passwd-m "$ {ip}: mysql is shutdown and slave error"
Fi
########### ########################
$ Ip is used to obtain the IP address of the Local Machine
$ Port is used to determine whether the mysql service is running normally.
$ Array is an array, $ array [0] is the first parameter in the array, and $ array [1] is the second parameter in the array.
If... then... fi can be monitored based on the obtained parameters.
$ {Ip}: mysql is shutdown and slave error # note that the master node fails to replicate because mysql is not running normally.
######################################## ###############################
Finally, grant the executable permission to the script and run it every 15 minutes using crontab-e.
*/15 */home/shell/mysqm-s.sh
This article from the "game technology blog" blog, please be sure to keep this source http://youzao.blog.51cto.com/3946111/743328