Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to see all the parents of a device in reverse order

Status
Not open for further replies.

sbix

IS-IT--Management
Nov 19, 2003
493
0
0
CA
Hi everybody,
I am not sure if I have seen something like in the subjet here or in another forum.
I am looking for a script or something capable to walk the device list in reverse order from the child device up to "sys0".
I do know it is possible... I did something some time ago... but.. often I can hardly remember even my name... B-(
 
Perhaps a script like this:

Code:
#!/bin/ksh
dev=$1
echo $dev
while ! expr "$dev" : "sys0"
do
 dev=$(lsdev -Cl $dev -F parent)
 echo $dev
done

And call this script passing the device as parameter.

I haven't tried it, but it should work (be careful with non existent devices).
 
I use this in my DLPAR script to find the parent:

Code:
while [[ $DEV != pci* ]]; do
  SLOT=$(lscfg -l $DEV | awk '{print $2}')
  DEV=$(lsdev -C -F parent -l $DEV)
done
/usr/sbin/rmdev -R -l $DEV

Regards,
Khalid
 
Mixed Khalidaaa's one with mine, and checking for undefined devices:

Code:
#!/bin/ksh
dev=$1
echo $dev
devstat=$(lsdev -C -F status -l ${dev} 2>/dev/null)
if [[ $devstat != Available && $devstat != Defined ]]
then
 echo "$dev undefined"
else
 while [[ $dev != sys0 ]]
 do
  dev=$(lsdev -Cl $dev -F parent)
  echo $dev
 done
fi
 
Thanks everybody.
Khalida... the final rmdev would be a little dangerous in a sort of QUERY command....
But the main idea is correct.
 
Well, for a DLPAR environment (as Khalidaaa stated), it is quite normal to logically remove devices (e.g. a tape or optical drive) and their ancestors (hence [tt]rmdev -R -l <top_parent_device>[/tt]) in order to move the physical device to another LogicalPARtition.
Nothing dangerous about that, the devices are only set to "Defined" instead of "Available", so that they can be unpresented to the current LPAR, presented to another and discovered there...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top