#!/bin/bash
for ip in 192.168.1.{1..254};
do
(
ping $ip -c 6 &> /dev/null;
if [ $? -eq 0 ];then
echo $ip is alive
fi
) &
done
wait
未加() &之前,程序运行至少需要比较长的时间。加入() 与 &可以让程序同时运行,加快程序运行的速率。
#!/bin/bash
for ip in 192.168.1.{1..254};
do
(
ping $ip -c 6 &> /dev/null;
if [ $? -eq 0 ];then
echo $ip is alive
fi
) &
done
wait
未加() &之前,程序运行至少需要比较长的时间。加入() 与 &可以让程序同时运行,加快程序运行的速率。
转载于:https://my.oschina.net/zhuangweihong/blog/330227