pingHost.sh
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
AGENT_HOME=$1
HOST_FILE=$2
IS_LOGIN=$3
PINGCMD=""
# init ping command for diff OS
init(){
case `uname -s` in
Linux)
PINGCMD="ping -c 3 #IP_ADDR#"
;;
SUN)
PINGCMD="ping -s #IP_ADDR# 32 3"
;;
HP)
PINGCMD="ping #IP_ADDR# 32 3"
;;
*)
echo "Cannot get this system type!"
exit
esac
}
# login host, check host name is changed
login(){
tmprunstat=0
if [[ "$5" = *ssh* ]]; then
echo "Start ssh host:$2"
tmpDeviceId=`perl sshHost.pl $1 $2 $3 $4 | awk '{print $2}'`
if [ "$tmpDeviceId" = "$1" ]; then
echo "Compare right:$tmpDeviceId==$1!"
tmprunstat=1
else
echo "Compare error:$tmpDeviceId==$1!"
tmprunstat=2
fi
elif [[ "$5" = *telnet* ]]; then
echo "Start telnet host:$2"
tmpDeviceId=`perl telnetHost.pl $1 $2 $3 $4 | awk '{print $2}'`
if [ "$tmpDeviceId" = "$1" ]; then
echo "Compare right:$tmpDeviceId==$1!"
tmprunstat=1
else
echo "Compare error:$tmpDeviceId==$1!"
tmprunstat=2
fi
else
tmprunstat=2
fi
return $tmprunstat
}
writeSwap(){
echo "New KPI: $1 $2 $3 $4"
sh $AGENT_HOME/bin/WriteSwap.sh "$1" "$2" "$3" "$4"
}
pingHost(){
pingcmd=$1
i=0
tmprunstat=0
while (( $i < 3 ))
do
echo "start the $i circle"
iRate=`eval $pingcmd | grep "packet loss" | awk -F ',' '{print $(NF-1)}'| awk '{print $1}'`
echo "iRate==$iRate"
if [ $iRate = "100%" ]; then
tmprunstat=0
else
if [ $IS_LOGIN = "Y" ]; then
login $2 $3 $4 $5 $6
tmprunstat=$?
break
else
tmprunstat=1
break
fi
fi
let "i++"
done
return $tmprunstat
}
# init PINGCMD
init
cat $HOST_FILE | while read deviceId ipAddr userName password loginType unitId
do
status=""
tmpCmd=${PINGCMD/"#IP_ADDR#"/$ipAddr}
echo "$tmpCmd"
pingHost "$tmpCmd" $deviceId $ipAddr $userName $password $loginType < /dev/null
tmpstatus=$?
if [ $tmpstatus -eq 0 ]; then
status="DOWN"
elif [ $tmpstatus -eq 1 ]; then
status="UP"
elif [ $tmpstatus -eq 2 ]; then
status="UnKnown"
fi
writeSwap "$unitId" "FM-00-01-001-01" "$status" 29950
echo "======================================================================================================"
done
rm $HOST_FILE