pingall脚本
p i n g a l l:一个按照/ e t c / h o s t s文件中的条目逐一p i n g所有主机的脚本
它能够按照/ e t c / h o s t s文件中的条目逐一p i n g所有的主机。该脚本列出/ e t c / h o s t s文件并查找其中的非注释行(不以#开头的行)。然后使用一个w h i l e循环读入所有的行,接下来使用a w k分析出每行的第一个域,并把它赋给变量A D D R。最后使用f o r循环逐一p i n g相应的地址。
#!/bin/sh
#pingall
cat /etc/hosts|grep -v "^#"|while read LINE
do
ADDR=`awk '{print $1}'`
for MACHINE in $ADDR
do
ping -s -c $MACHINE
done
done