#!/bin/bash
#判断主机存活 三次机会
#v1.0 by hujianmei 2020223
ip_list="10.18.40.1 10.12.122.2 10.34.23.1 www.baidu.com"
for ip in $ip_list;do
for count in {1..3};do
ping -c1 -W1 $ip &>/dev/null
if [ $? -eq 0 ];then
echo "$ip ping is ok"
break
else
echo "$ip ping is failure: $count"
fail_count[$count]=$ip
fi
done
if [ ${#fail_count[*]} -eq 3 ];then
echo "${fail_count[1]} ping is failuer!--------------- "
fi
unset fail_count[*]
done
#!/bin/bash
#判断主机存活 三次机会
#v2.0 by hujianmei 20200223
while read ip;do
fail_count=0
for count in `seq 1 3`;do
ping -c1 -W1 $ip &>/dev/n
(1) 判断主机存活 三次机会 以下为三个版本#!/bin/bash#判断主机存活 三次机会#v1.0 by hujianmei 2020223ip_list="10.18.40.1 10.12.122.2 10.34.23.1 www.baidu.com"for ip in $ip_list;do for count in {1..3};do ...