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!

for loop command 3

Status
Not open for further replies.

geoffinva3

Technical User
Feb 15, 2005
9
US
Ok I don't have a million years to learn unix scripting

I just need the syntax to use the for loop command

I have a file with a list of IP addresses in it
I want to excute the command ping on each address in the list. In addition it should output to a file where I see the ip address of each and the result of ping.


Can anyone bail a guy out

Thanks!!!
 
man your shell

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok I don't have a million years to learn unix scripting

ok, that's fair - how many years DO you have?

here's something to start with - assuming one IP per line in the file:
Code:
#!/bin/ksh

fileIPs='/path/to/the/IPfile'

while read ip
  ping "${ip}"
done < "${fileIPs}"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
in addition to vgersh99's post, do a "man ping" in order to delimitate the ping output. ping some_host will generate a endless list for only one host. you should use something like "ping -c 2 host" .. it means, ping twice to the host.

Cheers.
 
You guys are the best if you ever need SNMP assistance please write.

Geoff
 
OK thanks for the help yesterday. I decided to use some of my time for better use. I went home last night and learned something if you can beiev it. and by god it worked it printed each line to standard out. Now I want to change it to read the line and than execute the ping command on each any ideas?

I tried Perl and wrote the following bit of code:


1: #!/usr/local/bin/perl

2:

3: if (open(MYFILE, "file1")) {

4: $line = <MYFILE>;

5: while ($line ne "") {

6: print ($line);

7: $line = <MYFILE>;

8: }


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top