1 vim /etc/keepalived/check_MySQL.sh 2 #!/bin/sh 3 #isok=$(sed -n '2p' /etc/keepalived/result.txt) 4 isok=$(/usr/local/mysql/bin/mysql -uroot -p123456 -e 'select 1' |sed -n '2p') 5 function error_query(){ 6 service keepalived stop 7 echo "172.16.16.34 mysql down, keepalived 切换" | mail -s "34MySQL+keepalived通知" ma.xiangqian@sf-express.com 8 } 9 echo "$isok" 10 if [ "$isok" != "1" ] 11 then 12 #echo 'diaoyong error' 13 error_query 14 fi