mysql 的一個監控指令碼,監控heartbeat

season0891發表於2010-10-11
[root@idc-d-1545 hbmon]# cat mon.sh
#!/bin/bash
trap 'echo  PROGRAM INTERRUPTED; exit 1'  INT
username=hbuser
password=hbuserpwd
n=0
echo >mysqlmon.log
while true;
do
   if /usr/local/mysql/bin/mysql  -u$username -p$password -e "use test"   >&/dev/null;
      then
        echo `date +"%Y-%m-%d  %H:%M:%S"`  mysqld is alive!  >>mysqlmon.log
        n=0
      else
        echo  `date +"%Y-%m-%d  %H:%M:%S"`  mysqld  cannot be  connected!  >>mysqlmon.log
        n=$[n + 1]
        if [ $n -eq 3 ] ; then
           service heartbeat stop
           echo  `date +"%Y-%m-%d  %H:%M:%S"`  mysqld  switched to backup!  >>mysqlmon.log
           break
        fi
      fi
  sleep 10
done
[root@idc-d-1545 hbmon]#

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-675708/,如需轉載,請註明出處,否則將追究法律責任。

相關文章