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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cat file to ping

Status
Not open for further replies.

cmarchman

Programmer
Jun 18, 2004
56
US
Here's the situation:

I'm trying to get the IP Addresses from the system names via a quick commandline script "cat file | while read line; do ping -c3 $line; done"

I get ping: unknown host <system name in the file>

However, when I do 'ping -c3 <system name in the file>' from the commandline I see the results of the ping as expected.

So, it seems that the name resolution works when individually done on the commandline, but when done within the script it doesn't resolve the name.

I've run it as 'root' and as a normal user.

Any thoughts?

Thanks,

cmarchman
 
Are you including the qoutes when you type that in?

You could try this to from ksh/sh/bash:
Code:
for LINE in `cat /file/name`
do
     ping -c3 ${LINE}
done
 
Sounds like there may be invisible characters surrounding the hostnames in your file.

Also, why use ping? Why not use "nslookup" or "dig" or "host"?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top