#!/bin/sh
#
# vg2xp.sh
#
# Shows all XP LUs associated with one or more Volume Groups
#
# CAVEAT: VGs which are not active do not show up! Careful if you
#         use this to clean up unused LUs, as they might be in a
#         deactivated VG (which is common in a ServiceGuard cluster)
#
# 2005/04/22 Olivier S. Masse, omasse ~at~ mayoxide ~dot~ com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

host=$(hostname)
tempfile=/tmp/vg2xp.$$

echo "please wait..." >&2
/usr/contrib/bin/xpinfo -il >$tempfile

# If one or more vgs are given as options, onlt these VGs will be checked.
# by default it checks all of them
vglist="$*"

vgdisplay -v $vglist | awk '/VG Name/ {print $3}' | while read vg
do
	vgdisplay -v $vg | awk '/PV Name/ {sub(/dsk/, "rdsk", $3); print $3;}' | while read pv
	do
		lu="$(grep $pv $tempfile | awk '{print $6, $7, $8}')"
		if [ "$lu" = "" ]
		then
			echo "$host ... (unassigned) ... $pv $vg"
		else
			echo "$host $lu $pv $vg"
		fi
	done
done | sort -k 2,2

rm $tempfile


