Question

I have several hundred HP Onboard Administrator devices to audit for firmware revision and serial numbers. I have managed to get sshpass & ssh working to remotely logon and run the "show oa info" command remotely, which pulls back output along these lines:

$ sshpass -p password ssh -o UserKnownHostsFile=/dev/null 
-o StrictHostKeyChecking=no logon@OA_Name1 'show oa info'

Onboard Administrator #1 information:
    Product Name  : BladeSystem c7000 DDR2 Onboard Administrator with KVM
    Name          : OA_Name1
    Part Number   : 456204-B21
    Spare Part No.: 503826-001
    Serial Number : 12345678
    UUID          : 12345678
    Manufacturer  : HP
    Firmware Ver. : 3.31 May 23 2011

What I would like to do is extract certain lines and convert to CSV data so I can export to a spreadsheet for management to see.

I have tried using grep, sed and awk, and have been failing miserably so far, I wondered if someone could offer some help? The overall output varies depending on the version of the HP software, but it always has the Name, Serial Number & Firmware Ver fields

Ideally, it would end up similar to:

Name,Serial Number,Firmware Ver,
OA_Name1,12345678,3.31 May 23 2011,
OA_Name2,12345678,3.31 May 23 2011,

Many thanks in advance.

Dave

Was it helpful?

Solution 2

Like this with awk:

yourcommand | awk -F: '/Name/{n=$2} /Serial/{s=$2} /Firmware/{f=$2} END{printf "%s,%s,%s\n",n,s,f}'

So, if awk sees Name, it saves the second field in the variable n. If it sees Serial, it saves the second field in variable s. If it sees Firmware, it saves the second field in f. At the end it prints n,s,f.

The -F: sets the field separator to a colon.

OTHER TIPS

Do you need like this?

yourcommand | sed -n 's/^[ ]*\(Name\|Serial Number\|Firmware Ver.\)[ ]*:\(.*\)/\2/p' | tr '\n' ','
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top