读书人

将/etc/hosts资料中的所有地址都ping

发布时间: 2012-07-23 09:42:19 作者: rapoo

将/etc/hosts文件中的所有地址都ping 2次
修改下面 Shell 脚本中的两处错误,
程序本意:将/etc/hosts文件中的所有地址都ping 2次






Shell 脚本如下:
#/usr/bin/sh
#grad /etc/hosts and ping each address
cat /etc/hosts | grep -v '^#' | while read LINE
do
ADDR=`awk '{print $1}'`
for MACHINE in $ADDR
do
ping $MACHINE -n 2
done
done


多谢了


[解决办法]
除了镜花水月说的,下面的for循环没必要
for MACHINE in $ADDR
do
ping $MACHINE -n 2
done
只有1个ip,直接ping -c 2就行

读书人网 >UNIXLINUX

热点推荐