#!/bin/bash
#-------------CopyRight-------------
# Name:MySQL Check master and slave
# Version Number:1.00
# Type:sh
# Language:bash shell
# Date:2018-05-09
# Author:xubing
# QQ:442656067
# Email:eeexu123@163.com
# Blog:https://www.cnblogs.com/eeexu123/
Port=3306
User="root"
#Password="oldboy123" //MySQL用户密码
Mysql_sock="/tmp/mysql.sock"
Mysql_cmd="mysql -u${User} -e"
Error_file="/tmp/mysql_check_error.log"
#source functions libary
. /etc/init.d/functions
#check mysql server //检查MySQL是否启动
[ -e $Mysql_sock ]||{
echo "The Mysql server no start"
exit 1
2,0-1 Top
#check mysql slave //检查从库是否正常
check_mysql(){
array1=(`${Mysql_cmd} "show slave status\G"|egrep "Slave_IO_Running|Slave_SQL_Running|Last_SQL_Errno|Seconds_Behind_Master"|awk '{pr
int $NF}'`)
if [ "${array1[0]}" = "Yes" -a "${array1[1]}" == "Yes" -a "${array1[2]}" = 0 ];then
action "Mysql Slave" /bin/true
else
action "Mysql Slave" /bin/false
if [ "${array1[0]}" != "Yes" ];then
${Mysql_cmd} "show slave status\G"|grep "Slave_IO_Running">>$Error_file
elif [ "${array1[1]}" != "Yes" ];then
${Mysql_cmd} "show slave status\G"|grep "Slave_SQL_Running"|grep -v "Slave_SQL_Running_State">>$Error_file
else [ "${array1[2]}" != 0 ]
${Mysql_cmd} "show slave status\G"|grep "Seconds_Behind_Master">>$Error_file
fi
skip_errors ${array1[3]}
fi
}
main(){
while true
do
check_mysql
sleep 60
done
}
main
检查mysql主从复制脚本
最新推荐文章于 2022-07-26 14:16:10 发布