Operating System - Linux
1753821 Members
8913 Online
108805 Solutions
New Discussion юеВ

Merge 2 scripts to one output

 
SOLVED
Go to solution
Peter Lachnitt
Advisor

Merge 2 scripts to one output

Hi,

I found 2 scripts (laninfo & lanspeeed).
I want to merge this 2 scripts to one and one output but I dont now how. This scripts have to run on hpux 10.20 & 11.11.
laninfo:

Device IP MAC Hostname in /etc/hosts
-------------------------------------------------------------------------------
lan0 NONE 08:05:09:A3:38:96 NONE
lan1 30.230.14.3 01:33:6E:27:89:95 hp00003


lanspeed:
Card at PPA 0 - IP Address: Not assigned -
Card at PPA 1 - IP Address: 30.230.14.3 - Config = 100 Full-Duplex MANUAL

Wanted output:
Device IP MAC Hostname speed auto/manual
-------------------------------------------------------------------------------
lan0 NONE 08:05:09:A3:38:96 NONE
lan1 30.230.14.3 01:33:6E:27:89:95 hp00003 100 manual

Hope you can help.

Peter Lachnitt
3 REPLIES 3
Jean-Yves Picard
Trusted Contributor

Re: Merge 2 scripts to one output

hello,

merge.awk is
/Card/ { info[$8] = substr($0,index($0,"=")) ; next ;}
{ printf "%s %s \n",$0,info[$2] ; }

you launch with
( ./lanspeed.sh ; ./laninfo.sh ) | awk -f merge.awk
Device IP MAC Hostname in /etc/hosts
-------------------------------------------------------------------------------
lan0 NONE 08:05:09:A3:38:96 NONE
lan1 30.230.14.3 01:33:6E:27:89:95 hp00003 = 100 Full-Duplex MANUAL

you can adjust what is printed in substr($0,index($0,"="))

Jean-Yves
Matti_Kurkela
Honored Contributor
Solution

Re: Merge 2 scripts to one output

Here's my version.

The requirement to run it on 10.20 made it a bit tricky: on 10.20 lanadmin requires NMID, on 11.00 and above it uses PPA numbers.

Besides, on 10.20 it seems the duplex and autonegotiate values can't always be detected. This will print out question marks to the appropriate columns in that case.

I know you did not ask the full/half duplex info, but I threw it in anyway... :-)

The speed value has 5 spaces, so it should handle 10gig NICs if they can be queried the same way.

On 11.00 and 11.11 there may be variations in the format of "lanadmin -x " output, but it should be easy to modify the script to cope with them.

Duplex is two letters, either HD or FD.
Auto/manual is just one letter, so it is A/M. I wanted to keep the line length in 80 characters, so it won't look ugly on a standard console terminal.
MK
Peter Lachnitt
Advisor

Re: Merge 2 scripts to one output

Thanks Jean-Yves & Matti

Matti you are the best. Your version is working and gives my the output that I wanted.

Peter
Peter Lachnitt