O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

27.1. pingall

I wrote pingall quite a few years ago as part of a general reporting script that ran during the night. It pings all the hosts held in the hosts file.

The script cats the /etc/hosts file and greps out all lines that do not begin with a #.A while loop then reads in lines of filtered text. Awk is used to assign the first field of the filtered text to the variable ADDR. Using a for loop, each address is then pinged.

Here’s the script.

						$ pg pingall 
#!/bin/sh 
# pingall 

# grab /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 -s -c1 $MACHINE 
  done 
done 

The pingall script can easily expanded to include reporting functions of other network utilities. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required