#!/bin/sh
#check_mysql_slave status
Ip=eth1 #网卡名称
Mysql_binfile=/usr/local/mysql/bin/mysql
Mysql_user=root #MySQL数据库账号
mysql_pass=123456 #密码
Mysql_sockfile=/tmp/mysql.sock
Datetime= ' date + '%y-%m-%d/%h:%m:%s ' #获取当前时间
Mysql_slave_logfile=/opt/slave.log #日志文件路径 must be created in advance.
slave_ip= ' ifconfig $ip |grep "inet addr" | awk-f[: ""]+ ' {print $4} '
status=$ ($mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "show slave status\g" | grep-i "Running")
Slave_io_running= ' echo $status | grep slave_io_running | awk ' {print $} '
Slave_sql_running= ' echo $status | grep slave_sql_running | awk ' {print $} '
If ["$Slave _io_running" = "yes"-a "$Slave _sql_running" = "yes"]
Then echo "Slave is running!" >>/opt/s.log
#mail-S "$ip Slave is running! (The master-slave relationship is normal and safe to use.) ) "243652136\ @qq. com </opt/s.log
Else
echo "$datetime $slave _ip slave is not running!" >> $mysql _slave_logfile
Mail-s "Slave is not running! (Master-slave relationship down, hurry to repair it.) ) "243652136\ @qq. com < $mysql _slave_logfile
$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "Stop slave;"
$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "set global sql_slave_skip_counter=1;"
$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "start slave;"
$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "Exit"
Fi
This article is from the "System website Operations" blog, please be sure to keep this source http://cgc243652136qq.blog.51cto.com/3989433/1829623
MySQL master-slave relationship monitoring, fault alarm and recovery