#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/diag/da/disks/dgvars.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1989,1991 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)41	1.4  src/bos/diag/da/disks/dgvars.sh, dadisks, bos720 9/28/06 13:53:15
#
# COMPONENT_NAME: (CMDDIAG)  DISK DA LVM Query
#
# FUNCTIONS: Processes LV HLC output for disk DAs
#
# ORIGINS: 27
#
# (C) COPYRIGHT International Business Machines Corp. 1989, 1991
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#                                                                   
###################################################################

findval ()
{
	/usr/bin/awk '
	{
		#print "DEBUG nm= " nm
		n = index($0, nm);
		#print "DEBUG n= " n
		if( n >= 1 ) {
			n = n + length( nm );
			$0 = substr( $0, n+1);
			print $1
		}
	}
	' nm="$1"
}
if [ $# -ne 1 ]; then
	echo Usage: $0 pv-name >&2
	exit 7
fi

DIAGDATA=/etc/lpp/diagnostics
DIAGDATADIR=$DIAGDATA/data

pv_name=$1
pvls_file=$DIAGDATADIR/d.lspv
vgls_file=$DIAGDATADIR/d.lsvg
trap "/usr/bin/rm -f ${pvls_file} ${vgls_file}"		0
trap "/usr/bin/rm -f ${pvls_file} ${vgls_file}; exit"	1 2 3 15

/usr/sbin/lspv ${pv_name} > ${pvls_file}
if [ $? -ne 0 ]; then
	exit 101
fi

VOLGROUP=`	findval "VOLUME GROUP:"		< ${pvls_file}`
NDESCPV=`	findval "VG DESCRIPTORS:"	< ${pvls_file}`

## echo $VOLGROUP $VGDSPV
/usr/sbin/lsvg ${VOLGROUP} > ${vgls_file}
if [ $? -ne 0 ]; then
	exit 102
fi

TOTALPVS=`	findval "TOTAL PVs:"		< ${vgls_file}`
ACTIVEPVS=`	findval "ACTIVE PVs:"		< ${vgls_file}`
NDESCVG=`	findval "VG DESCRIPTORS:"	< ${vgls_file}`

echo $VOLGROUP
echo $NDESCPV
echo $TOTALPVS
echo $ACTIVEPVS
echo $NDESCVG
exit 0
