#!/bin/bash
#data=2018-
ROOT="root"
PASSWORD="123456"
##在主庫查詢從節點是否存活
##SLAVE_IPS=$(mysql -uroot -p123456 -e "select * from information_schema.processlist as p where p.command = 'Binlog Dump';" |awk '{print $3}' |sort -n| awk -F: '{print $1}' |grep -v HOST)mysql
#在從庫查詢主從的狀態
Slave_IO_Running=$(mysql -u${ROOT} -p${PASSWORD} -e "show slave status\G;" | grep "Slave_IO_Running" |awk '{print $2}')
Slave_SQL_Running=$(mysql -uroot -p123456 -e "show slave status\G;" | grep "Slave_SQL_Running" |awk '{print $2}')
if [ "${Slave_IO_Running}" = "Yes" -a "${Slave_SQL_Running}" = "Yes" ];then
echo "數據庫主從復未異常"
else
echo "The Slave_SQL_Running is ${Slave_SQL_Running}, and the Slave_IO_Running ${Slave_IO_Running}"
echo "please run 'show slave status\\G;' in mysql"sql
fi數據庫