分类: 服务器与存储
2008-06-07 18:00:12
[root@node1 ~]# cat monitor.sh #Monitor.sh #!/bin/bash email=xxxx@xxxx.com ip=$1 port=$2 if [ "$#" != 2 ] then echo "USEAGE:./`basename $0` exit 0 fi telnet $ip $port > /tmp/monitor.tmp << pass quit pass cat /tmp/monitor.tmp |grep 'Escape character' > /dev/null if [ "$?" = 0 ] then echo "`date |awk '{print $6"."$2"."$3"."$4}'`:port is listening" >> /var/log/ha_log/monitor.log /etc/init.d/heartbeat status|grep "heartbeat OK" >> /dev/null if [ "$?" = 1 ] then /etc/init.d/heartbeat start fi else echo "`hostname`:$port is not listening.And now forward to another active node"|mail -s "Warning:Cannot reach $ip:$port" $email /etc/init.d/heartbeat stop # echo "`date |awk '{print $6"."$2"."$3"."$4}'`:port is not listening" >> /var/log/ha_log/monitor.log fi |