检测主机的状态
#!/bin/bash
#description:检测主机的状态
ip_list="40.554.136.150 40.554.136.151"
for ip in $ip_list; do
if ping -c 1 $ip &>/dev/null; then
echo "$ip ok"
else
echo "$ip no!"
fi
done
有网络抖动时候处理方式:
#!/bin/bash
#description:检测主机的状态
ip_list="40.554.136.150 40.554.136.151 40.26.136.368 40.554.136.152 40.26.136.154"
for ip in $ip_list; do
NUM=1
while [ $NUM -le 3 ];do
if ping -c 1 $ip &>/dev/null; then
echo "$ip ok"
break
else
file_count[$NUM]=$ip
let NUM++
echo "$ip no!"
fi
done
#echo ${file_count[*]}
if [ ${#file_count[*]} -eq 3 ]; then
echo "${file_count[1]} ping is file!"
unset file_count[*]
fi
done
输出:
[weblogic@test ml]$ sh test.sh
40.554.136.150 ok
40.554.136.151 ok
40.26.136.368 no!
40.26.136.368 no!
40.26.136.368 no!
40.26.136.368 ping is file!
40.554.136.152 ok
40.26.136.154 no!
40.26.136.154 no!
40.26.136.154 no!
40.26.136.154 ping is file!