批次檢查主機是否可達的ping指令碼.

tengrid發表於2010-01-15

注意,dwpri/dwstb/dwisd/dwied/bmdmk/dwbi/bistb對應的ip要放到hosts中

指令碼發兩個包去探測,基本上可以準確知道機器是否可達.
#more ping.sh
#!/bin/sh

case "$1" in
dwpri|dwstb|dwisd|dwied|bmdmk|dwbi|bistb)
#send 2 packets to ping
if [ $1 = "dwpri" -o $1 = "dwstb" ];then
nodeNUM=24
elif [ $1 = "dwisd" -o $1 = "dwied" -o $1 = "bmdmk" ];then
nodeNUM=8
elif [ $1 = "dwbi" -o $1 = "bistb" ];then
nodeNUM=4
fi

pkgCNT=2

while [ $nodeNUM -gt 0 ];
do
loss=`ping -c$pkgCNT $1${nodeNUM} |grep "loss"|awk '{print $6}'|awk -F% '{print $1}'`
if [ $loss -eq "100" ];then
echo $1$nodeNUM" is DOWN!"
else
echo $1$nodeNUM" is active"
fi
echo "===================$1${nodeNUM}===================";
(( nodeNUM -= 1 ));
done
;;
*)
echo "Usage: $0 {dwpri|dwstb|dwisd|dwied|bmdmk|dwbi|bistb}"
exit 1
;;
esac

[@more@]

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

相關文章