顯示具有 ping 標籤的文章。 顯示所有文章
顯示具有 ping 標籤的文章。 顯示所有文章

2012年12月21日 星期五

活用fping監控大量機器的狀態

由於需要管理手中機器的存活狀態,找到了fping這個方便的指令來做這件事情,把需要監控的機器IP寫在一份.txt檔案中,格式如下:

100.65.206.219
100.65.206.220
100.65.206.221
100.65.206.222
100.65.206.223

接著執行這行指令,我在後面加上了

grep unreachable
是因為我只需要知道掛掉的機器是哪些,其中 -r 這個參數是retry的次數, -t 是timeout的長度(in millisec)。
# -r: retry count
# -t: timeout interval (in millisec)
sudo fping -f ip.txt -r 2 -t 50 | grep unreachable
當然,fping不只如此,他還可以指定要掃描的起始IP跟結束IP,或者是指定子網路遮罩。
fping -g 100.65.206.219 100.65.206.223
fping -g 100.65.206.0/24

2011年3月10日 星期四

#!/bin/sh
# Author: Norman
ARRAY=( Frank   1.2.3.4 \
        Norman  1.2.3.5 )
SYSTEM=`uname -s`
LOG=/tmp/wn_ntpdate.log.$$
i=0
while [ $i -lt 3 ] ; do
        NAME=${ARRAY[$i]}
        IP=${ARRAY[$i+1]}
        echo -n $NAME $IP ' '
        case $SYSTEM in
        Linux)
                ping -c 1 $IP 1> $LOG 2>&1
                ;;
        CYGWIN*)
                ping $IP 64 1 1> $LOG 2>&1
                ;;
        *)
                exit 1
                ;;
        esac
        if [ $? -eq 0 ] ; then
                case $SYSTEM in
                CYGWIN*)
                        grep "100.0% packet loss" $LOG 1> /dev/null 2>&1
                        if [ $? -eq 0 ]; then
                                echo failed
                        else
                                echo ok
                                scp wn_ntpdate.sh wn_ntpdate.cron test@$IP:/home/test/workspace
                                echo "Executing ntpdate command..."
                                ssh test@$IP 'sudo sh /home/test/workspace/wn_ntpdate.sh'
                                ssh test@$IP 'sudo rm -f /home/test/workspace/wn_ntpdate.sh'
                                ssh test@$IP 'sudo mv /home/test/workspace/wn_ntpdate.cron /etc/cron.hourly'
                                echo "#####" [$NAME:$IP] RS Test Environment \(Worker Nodes\) ntpdate Sucess "#####"
                                echo ""
                        fi
                        ;;
                Linux)
                        echo ok
                        scp -q wn_ntpdate.sh wn_ntpdate.cron test@$IP:/home/test/workspace
                        echo "Executing ntpdate command..."
                        ssh test@$IP 'sudo sh /home/test/workspace/wn_ntpdate.sh'
                        ssh test@$IP 'sudo rm -f /home/test/workspace/wn_ntpdate.sh'
                        ssh test@$IP 'sudo mv /home/test/workspace/wn_ntpdate.cron /etc/cron.hourly'
                        echo "#####" [$NAME:$IP] RS Test Environment \(Worker Nodes\) ntpdate Sucess "#####"
                        echo ""
                        ;;
                *)
                        exit 1
                        ;;
                esac
        else
                echo failed.
                echo ""
        fi
        ((i++))
        ((i++))
done
#rm -f $LOG
exit
Reference: Norman

2011年2月16日 星期三

Ping hosts using shell script

#!/bin/sh 
# Author: Frank
ARRAY=( 
  ${USER1} ${USER1IP}\
  ${USER2} ${USER2IP})
SYSTEM=`uname -s`
LOG=/tmp/testping.log.$$
i=0
while [ $i -lt 31 ] ; do
  NAME=${ARRAY[$i]}
  IP=${ARRAY[$i+1]}
    echo -n $NAME $IP ' ' 
    case $SYSTEM in
      Linux)
        ping -c 1 $IP 1> $LOG 2>&1
        ;;
      CYGWIN*)
        ping $IP 64 1 1> $LOG 2>&1
        ;;
      *)
        exit 1
        ;;
      esac
    if [ $? -eq 0 ] ; then
      case $SYSTEM in
        CYGWIN*)
          grep "100.0% packet loss" $LOG 1> /dev/null 2>&1
          if [ $? -eq 0 ]; then
            echo failed
          else
            echo ok
          fi
          ;;
        Linux)
          echo ok
          ;;
        *)
          exit 1
          ;;
        esac
    else
        echo failed.
    fi
    ((i++))
    ((i++))
done
#rm -f $LOG
exit
Reference: Frank