#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/clvpathpvids.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2002,2004 
# 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 
#/bin/ksh
# @(#)77        1.4 src/43haes/usr/sbin/cluster/cspoc/utilities/clvpathpvids.sh, hacmp.cspoc, 61haes_r714 3/12/04 10:08:49
# $Id$
# @(#)59  1.0.0.0  src/43haes/usr/sbin/cluster/cspoc/utilities/clvpathpvids.sh, hacmp.cspoc, 51haes_r510 6/21/02 19:50:09
###############################################################################
#
# Name:
#       clvpathpvids
#
# Description:
#   The clvpathpvids utility generates a combination of lspv and lsvpcfg commands
#   output. If vpath assosiated with the hdisk does not have yet a PVID,
#   utility takes the PVID from the related hdisk.
#   Result output is a list of lines, each of those contains a PVID number,
#   vpath name, volume group assosiated, and then the rest of lsvpcfg output.
#
#   Usage: clvpathpvids
#
# Arguments:
#	None
#
# Return Values:
#       0       success
#       1       failure
#
################################################################################


# Run lsvpcfg and read from it line by line separatin VPATH name
lsvpcfg | (while read VPATH REST ; do

	#For each vpath look for it in lspv output
        lspv | grep $VPATH | read VPATH_NAME PVID VG

	#If no PVID assosiated, the
        if [ "$PVID" = none ] || [ -z "$PVID" ]; then

		#Look for the lsvpcfd output for hdisk name
                print $REST | cut -d"= " -f2 | cut -d' ' -f2 |
                        cut -d' ' -f1| read HDISK

		#Grep hdisk PVID from lsvp output
                lspv | grep $HDISK | read DISK PVID VG

                if [[ "$PVID" = "none" ]] ; then
		        lquerypv -h /dev/$HDISK 80 1 | cut -d' ' -f 4,5 | tr -d ' ' | read PVID
                fi
        fi

	#Store results in output string
        echo $PVID $VPATH $VG $REST
done)