【发布时间】:2013-01-16 16:49:10
【问题描述】:
我正在输出一个这样的域列表:
lastdomain=`ls -lah /var/www/vhosts | wc -l`
#the variables below will be used later
IP1=`ifconfig | grep "inet addr" | sed '1 ! d' | awk '{print $2;}' | cut -c 6-19`
IP2=`ifconfig | grep "inet addr" | sed '2 ! d' | awk '{print $2;}' | cut -c 6-19`
LIST=`ls -lah /var/www/vhosts | sed "4,$lastdomain ! d" | awk '{print $9;}' | grep -v 'chroot\|default\|.skel'`
我想 ping 每一个。这几乎可以工作:
for each in $LIST
do
echo "Attempting to ping $each..."
ping -c 1 $LIST > /dev/null 2>&1 #&& break
if [ "$?" -ne "0" ]; then
echo "Host $each is not reachable! "
else
break
fi
done
但是它们都返回为:
Host exampledomain.com is not reachable!
我做错了什么?
编辑:现在这样可以了,我需要删除以下内容以获取 IP 地址:
PING domain.com (IP.IP.IP.IP) 56(84) bytes of data.
64 bytes from domain.co.uk (IP.IP.IP.IP): icmp_seq=1 ttl=64 time=0.024 ms
--- domain.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.024/0.024/0.024/0.000 ms
【问题讨论】:
标签: bash list for-loop ping ls