Operating System - HP-UX
1821559 Members
2770 Online
109633 Solutions
New Discussion юеВ

Re: Shell , awk or perl script

 
SOLVED
Go to solution
KapilRaj
Honored Contributor

Shell , awk or perl script

Folks,

I am looking for a script which will print vg name associated with each physical volume on an hpux system.

It should scan all the volume groups & disks on the system (vgdisplay -v & ioscan -fnkC disk) and then format the output in the following format.

/dev/dsk/c0t6d0 vg00
/dev/dsk/c0t5d0 vg00
/dev/dsk/c0t1d0 none
/dev/dsk/c0t2d01 vg01

I tried writing a shell script but it is too long .. I am sure there could be a perl or awk solution to this. I would appreciate any help on this...

Regards,

Kaps
Nothing is impossible
5 REPLIES 5
Sundar_7
Honored Contributor

Re: Shell , awk or perl script



vgdisplay 2>/dev/null | grep "VG Name" | awk '{print $NF}' | xargs -n1 | while read VGNAME
do
vgdisplay -v ${VGNAME} | grep dsk | awk -v VG=${VGNAME} '{print $3,VG}'
done

If the disk is not displayed in the vgdisplayed, then either the disk is not currently part of any volume group, an alternate link that is not added to the VG or it is part of the volume group that is not active.

So, I dont know how useful traversing through the output of ioscan will be.
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: Shell , awk or perl script

Danger Will Robinson!!

Such a script is fraught with danger. How do you propose to determine that a disk is unused? Just because it isn't currently a part of LVM or VxVM doesn't mean that it is unused. You could be using raw devices -- a very common practice with databases and a less common practice with other applications. Moreover, even if the disk is unused on this system does not mean that it is not in use on another system. The only way that I ever do this is document, document, document so that I never have to ask "Now what does this disk or LUN do?".
If it ain't broke, I can fix that.
spex
Honored Contributor
Solution

Re: Shell , awk or perl script

Hi Kaps,

Give this semi-tested shell script a try:

#!/usr/bin/sh

for HWP in $(ioscan -FkC disk | cut -d: -f11)
do
set -A HWOUT $(ioscan -fnH ${HWP})
CAND=${HWOUT[((${#HWOUT[*]}-2))]}
RC=$(echo ${CAND} | grep -qE '^/dev/dsk/')
if [ "${RC}" -eq "0" ]
then
VG=$(pvdisplay ${CAND} 2>/dev/null |\
awk '{if($1=="VG"&&$2=="Name"){sub(/\/dev\//,""); print $3}}')
echo ${CAND} ${VG:-none}
fi
done

exit 0

I try to account for the case where ioscan detects a disk device that doesn't have a corresponding device file with the first usage of ioscan. Since none of my systems meets this criterion (and I don't feel like removing device files), some guesswork is involved here.

PCS
KapilRaj
Honored Contributor

Re: Shell , awk or perl script

I am going to try each of the given options and will give you a feedback and then assign points. All I am looking for is an LVM map [ Something equivalent to lspv of aix ]. I am not worried if they are used as raw. I just wanted to know if they are not used by LVM.

Thanks for your time and I will get back asap.

Regards,

Kaps
Nothing is impossible
KapilRaj
Honored Contributor

Re: Shell , awk or perl script

Thank you guys. spex had the script that I wanted. Thank you for your valuable time.

Regards, Kaps
Nothing is impossible