检测ip是否在线(并发执行)

方法一 

#方法一
#!/bin/bash
for ip in 172.16.28.{100..120}
do
        datetime=`date "+%F %T"`
        (ping $ip -c2 -i 0.5&> /dev/null && echo -e ""$datetime 在线: $ip"" >> ping.txt || echo -e ""$datetime ***离线: $ip***"" >> ping.txt)&
wait
done


方法二

#/bin/bash
. /etc/init.d/functions
for ip in 218.60.28.{100..120}
do
        ping $ip -c2 -i 0.5 > /dev/null 2>&1
        if [ $? = 0 ];then
                action "$ip" /bin/true
        else
                action "$ip" /bin/false
        fi
wait
done

 

 

posted @ 2018-05-30 14:36  消磨_时间  阅读(531)  评论(0)    收藏  举报