方法一
#方法一
#!/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