zabbix监控 MySQL主同从同步状态脚本

#!/bin/bash
#Desc:用于获取主从同步信息,判断主从是否出现异常,然后提交给zabbix
#Date: 2020-06-08

USER="用户名"
PASSWD="密码"
NAME=$1

function IO {
Slave_IO_Running=mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_IO_Running |awk ‘{print $2}‘
if [ $Slave_IO_Running == "Yes" ];then
echo 1
else
echo 0
fi
}

function SQL {
Slave_SQL_Running=mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_SQL_Running: |awk ‘{print $2}‘
if [ $Slave_SQL_Running == "Yes" ];then
echo 1
else
echo 0
fi

}

case $NAME in
io)
IO
;;
sql)
SQL
;;
*)
echo -e "Usage: $0 [io | sql]"
esac

zabbix监控 MySQL主同从同步状态脚本

上一篇:详解Windows平台搭建Androiod开发环境


下一篇:SQL高级查询