双机热备使用的端口脚本

874阅读 0评论2008-06-07 双机热备5753
分类:服务器与存储

公司要求 随便写了个
因为heartbeat自带的那个PING侦测实在几乎不能用。。。太简单了 几乎不能控制侦测服务
上MON又太麻烦 一堆PERL 看着头疼 自己写个SHELL来针对端口侦测
脚本如下
[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

自动执行侦测多端口 请写个FOR循环到CRONTAB里面
为什么是执行STOP HEARTBEAT 请参考HEARTBEAT特性 希望对各位有用

上一篇:IBM基于SERVERAID6M卡的Windows 2000版本双机热备安装方法
下一篇:Cisco 3640策略路由配置