Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Host File Scrutiny? 1

Status
Not open for further replies.

unable24

Technical User
Nov 15, 2001
13
US
Help,
I have a basic ping script that works fine - but I can only reference a host file with IP's only:

I would like to follow the IP's w/ a tab and the host name, but my script doesn't like this:

here is my script:

dat=`date +%m%d%y`
while read HOST
do
ping $HOST -n 2 > /users/bastir/tempfile.txt
if grep '100% packet loss' /users/bastir/tempfile.txt
then
echo "cannot ping $HOST" >> /users/bastir/pingbad.$dat
else
echo "can ping $HOST successfully" >> /users/bastir/pinggood.$dat
fi
done < /users/bastir/civdev.txt


my host file is named civdev.txt
 
You need to strip out the IP address when you read HOST :-

<snip>
while read HOST
do
IPADDR=`echo $HOST | awk '{print $1}'`
ping $IPADDR -n 2 > /users/bastir/tempfile.txt
</snip>

although you'll probably also want to strip out any comment lines ($IPADDR starting with &quot;#&quot;).
One by one, the penguins steal my sanity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top