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

shell script - while loop

Status
Not open for further replies.

joychinna

IS-IT--Management
Feb 19, 2003
2
0
0
US
Hi

I am new bee into shell scripting. Pls help me.

There is a file f1 which has machine names and ip address of each machine in 2 columns.

I would like to write a script to ping each machine name reading from f1 and if it pings then write the machine name on to f2 and if it does not ping then it should pickup the (second column )ip address and write the ipaddress on to f2. The output in f2 will be a single column with the combination of machne names and ipaddress.

Ex: cat f1;
abc 10.0.0.1
efg 10.2.0.3

new file F2:

abc
10.2.0.3

Can any one help me building this one.

Thanks in advance
 
#!/bin/ksh

while read line
do
set - `echo $line` # parse each line into $1 & $2
ping $1
if [ $? -eq 0 ]; then # check the exit status
echo $1 >> f2
else
echo $2 >> f2
fi
done < f1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top