Re: A fun little awk help. Legacy device getter. (134 Views)
Reply
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 1 of 10 (134 Views)
Accepted Solution

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
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 10 (134 Views)

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...
Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 3 of 10 (134 Views)

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
Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 4 of 10 (134 Views)

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
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 10 (134 Views)

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...
Please use plain text.
Honored Contributor
Viktor Balogh
Posts: 1,007
Registered: ‎03-15-2009
Message 6 of 10 (134 Views)

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.
Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 7 of 10 (134 Views)

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
Please use plain text.
Honored Contributor
Viktor Balogh
Posts: 1,007
Registered: ‎03-15-2009
Message 8 of 10 (134 Views)

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.
Please use plain text.
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 9 of 10 (134 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,389
Registered: ‎03-06-2006
Message 10 of 10 (134 Views)

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}')
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation