Get the ipaddress and align based on the input file

Hi All,

I have a file contains below contents, "interfacename/subnet: public (or) interfacename/subnet:cluster_interconnect"

"en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public
"en0"/10.26.208.0:public,"en1"/192.168.3.0:cluster_interconnect

With the help of the contents i want to make the ouput like below

  Public IP Address : 169.181.146.79
  Private IP Address 1 : 10.185.81.1
  Private IP Address 2 : 10.185.81.2

sometime it may have 2 cluster_interconnect & sometime it may be 1. Please provide the suggestions. Thanks !

Regards
Kamal

Your output data doesn't really resemble your input. It seems to create .79, .1, .2 out of nowhere -- how does it decide these from .0? Why does it ignore 10.26.208.0? etc, etc.

You'll have to explain the algorithm you want better.

Thanks for the reply, Let me rephrase my question. I need to get the interface name (example en2 -> private en5 -> private en6 -> public)based on those below input file and get the ipaddress for each interface name..... like that i have to do for each line of input file... and get the output as below.

Input file
---------

 
"en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public
"en0"/10.26.208.0:public,"en1"/192.168.3.0:cluster_interconnect

Expected Output
-----------------

  Public IP Address : 169.181.146.79
  Private IP Address 1 : 10.185.81.1
  Private IP Address 2 : 10.185.81.2

Regards
Kamal

Hi,

You could probably get the information this way;

# ifconfig -a

Regards

Dave

You have not explained anything about what I actually asked.

Where does the .79 come from?

Where does the .1 come from?

Where does the .2 come from?

Why does it ignore 10.26.208.0?

Why does it ignore 192.168.3.0?

What does the interface name have to do with any of it? It doesn't appear in the output at all.

Input data (Only single line) is generated by oracle database itself its stored in config file in each and every Oracle RAC Server as below format

 
ex:
if we specify one public & private interface during installation of oracle RAC it will put one entry for public and private as below format in config file 
 
"<interfacename>"/<subnet>:public,"<interfacename>"/<subnet>:cluster_interconnect
 
if we specify one public & two private interface during installation of oracle RAC it will put one entry for public and two private as below format in config file 
 
"<interfacename>"/<subnet>:public,"<interfacename>"/<subnet>:cluster_interconnect,"<interfacename>"/<subnet>:cluster_interconnect

All i am doing now is based on this input stored in the config file i want to convert this to below output

 
EX : ifconfig en2  (Ipaddress will be derived from this command)
 
en6 -> public -> <Ipaddress>
en2 -> Private 1 -> <Ipaddress>
en5 -> Private 2 -> <Ipaddress>

Regards
Kamal

Making the wild assumption (amongst others) that your ifconfig will produce sth like

eth0      Link encap:Ethernet  HWaddr 00:1f:c6:4c:d0:e2  
          inet addr:10.1.1.1  

this awk program (saved in cmdfile) might do the job:

BEGIN   {
         while (("ifconfig -a|awk '/Link/ {a=$1; getline; sub(\".*:\",\"\",$2);print a, $2}'"|getline) > 0)
         ip[$1]=$2
         RS="[,\n]"; FS="/"
        }

        {
         gsub("\"","");gsub("([0-9]+[.:])+","",$2); if($2!="public") $2="Private "++pn
        }
        {print $1, "->", $2, "->", ip[$1]}

Execute like awk -f cmdfile inputfile

What it does is in the BEGIN command it executes ifconfig to pipe all the interfaces (identified by "Link" in the same line) and their IP- addresses into array "ip". Then it reads your input file, records separated by ",", to extract the respective interface names, cleans field $2 from the network part, and, if the remainder is not "public", assigns the string "Private " plus a counter. Finally the fields are printed. Hope this fits your needs. You may need to adapt the ifconfig extraction.