日期:2014-05-16  浏览次数:20588 次

将/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就行