Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

A fun little awk help. Legacy device getter.

SOLVED
Go to solution
Highlighted
Steven E. Protter
Exalted Contributor

A fun little awk help. Legacy device getter.

Ouptput:

disk 29 0/6/2/0.151.15.23.0.0.4 sdisk CLAIMED DEVICE IBM 2145
/dev/dsk/c19t0d4 /dev/rdsk/c19t0d4


That is standard 11.23 ioscan.

I have the -H hardware device.

0/0/1/1.15.0

Which I got from setboot

I am needing the legacy device. Can't use ioscan -m because that useful little tool does not exist.

It will look kind of like:

I can't get the awk working today.


ioscan -kfnC fc | awk ‘/fcd/ {getline;fcd=$NF;print fcd,$2}’ | while read -r fdev
do

fcmsutil ${fdev} | awk ‘/Hardware / {print $5};/World / { print $7}’

done


Something like:
ioscan -kfnCdisk | awk '/$pboot/ {getline;fcd=$pboot; print fcd,$2}'

Except maybe something that works.

SEP

Was thinking:
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
9 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: A fun little awk help. Legacy device getter.

Hi SEP:

> ioscan -kfnCdisk | awk '/$pboot/ {getline;fcd=$pboot; print fcd,$2}'

If you are attempting to pass 'pboot' as a variable, this isn't gong to work. You should do something like:

# ioscan -kfnCdisk | awk -v pboot=${pboot} '$0~pboot {getline print pboot,$2}'

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: A fun little awk help. Legacy device getter.


ioscan -kfnCdisk | awk -v pboot=${pboot} '$0~pboot {getline print pboot,$2}'

I get the concept.

awk: The statement cannot be correctly parsed.
The source line is 1.

I'm hacking away here.

This looks almost done.

Steven
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: A fun little awk help. Legacy device getter.

Fixed it:

ioscan -kfnCdisk | awk -v pboot=${pboot} '$0~pboot {getline;print pboot,$2}'

Chime in JRF for full pointage.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor
Solution

Re: A fun little awk help. Legacy device getter.

Hi (again) SEP:

Oops, i forgot the semicolon :-) I meant:

# ioscan -kfnCdisk | awk -v pboot=${pboot} '$0~pboot {getline; print pboot,$2}'

...just as you deduced.

Regards!

...JRF...
Viktor Balogh
Honored Contributor

Re: A fun little awk help. Legacy device getter.

good to know how to import shell variables inside awk. I always used a much ugly way by alternating quotes and escape characters. :)

# ioscan -kfnCdisk | awk '/'$pboot'/ {getline;fcd='$pboot'; print fcd,$2}'
****
Unix operates with beer.
Steven E. Protter
Exalted Contributor

Re: A fun little awk help. Legacy device getter.

It was still kind of wrong.

abootdisk=$(ioscan -kfnCdisk | awk -v aboot=${aboot} '/aboot/ $0~aboot {getline;print aboot,$2}' | awk '{ print $2 }');

That is the final version.

Done, assigning points.

awk is awkful
awk is fun, more than enough for anyone.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Viktor Balogh
Honored Contributor

Re: A fun little awk help. Legacy device getter.

I've got two things what's not so clear to me:

why did you use both /aboot/ and $0~aboot ? both says "if the line contains the value of the variable aboot, do this..."

and why did you give the output to a second awk statement? (which could be done inside the first awk) that seems to me a performance hog.
****
Unix operates with beer.
Steven E. Protter
Exalted Contributor

Re: A fun little awk help. Legacy device getter.

I stopped working on this when it worked.

I will award points for working more efficient code.

The statement executes twice as part of a process that chooses alternate boot disk to be broken out of a two disk root/boot mirror set as a target for a DRD clone.

If it were executing hundreds of times, I would work harder on efficiency.

Its not, so I stopped. I am not averse to a theoretical exercise to improve the code.

The current code is the top new post at http://hpux.ws

I would love to tune it up and make it more awkful.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: A fun little awk help. Legacy device getter.

>Viktor: why did you use both /aboot/ and $0 ~ aboot?

I'm not sure what both really do together?

>both says "if the line contains the value of the variable aboot"

No, /aboot/ says look for the constant RE containing "aboot", not the variable. That's why JRF switched $0 ~ aboot

>why did you give the output to a second awk statement?

(I assumed the extra token was to make sure it worked?)
Not really done, just changed: :-)
... | awk -v aboot=${aboot} '$0 ~ aboot {getline; print $2}')