shell指令碼實現數據庫主從的狀態檢查

2020-08-12 21:30:05

準備:
mysql , mail

#!/bin/bash
a=`mysql -e 'show slave status \G' | grep Slave_IO_Running | awk -F ':' '{print$2}'`
b=`mysql -e 'show slave status \G' | grep Slave_SQL_Running | awk -F ':' '{print$2}'`
if [ $a -a $b==Yes ];then
        echo "主從正常"
else
        echo "主從失敗"
        echo "失敗" | mail -s "error" 12345679@qq.com
fi