準備:
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