#!/bin/ksh
#
# Summarize SecurePath Storage and LUN Usage
# N. Caparroso (circa 2004)
# Out of Frustration of the current state of Storage Management
# 7-22-05   Adapted for VxVM
#
STORAGE_LIST=/tmp/storage.$$
spmgr display|grep "Storage:"|awk '{print $2}'>$STORAGE_LIST

for array in `cat $STORAGE_LIST`;do
 spmgr display|grep $array
 echo =================================================================
 echo "AID   WWID                                    HPDEV   SIZE VGName       LVOLS..."

 AID=`spmgr display|grep $array|awk '{print $NF}'|sed 's/(//'|sed 's/)//'`
 LUNS=`spmgr display -rv $array|awk 'NF==5'|grep "/ "|awk '{print $3,$4}'`
 if [ -z "$LUNS" ];then
    echo "No LUNS Found!"
    echo
    continue
 fi
 set $LUNS
 # Get VGName and Data contained for each LUN
 while [ $# -gt 0 ]; do
   DISK=$1
   WWID=$2
   # Check if disk is okay
   diskinfo /dev/rdsk/${DISK} >/dev/null 2>&1
 if [ $? -eq 0 ]; then
   SZ=`diskinfo /dev/rdsk/${DISK}|grep size|awk '{print $2}'`
   GBSZ=$((SZ / 1024 / 1024))
   # Check if LUN belongs to a VG
   VG=`pvdisplay -v /dev/dsk/${DISK} 2>/dev/null|grep -i "vg name"|awk '{print $NF}'|sed 's/\/dev\///'`
   if [ -z "$VG" ];then
      #Check if it is part of a VxVM
      VG=`vxdisk -o alldgs list|grep ${DISK} 2>/dev/null|awk '{print $4}'`
      if [ "$VG" = "-" ];then
         VG="Not_in_a_VG"
         LV=""
      else
         LV=`vxdisk -o alldgs list|grep ${DISK} 2>/dev/null|awk '{print $3}'`
         LV="vx - $LV"
      fi
   else
      LV=`pvdisplay -v /dev/dsk/${DISK} 2>/dev/null|grep "current"|awk '{print $3}'|awk -F\/ '{print $NF}'|sort|uniq
`
   fi 
   echo $AID $WWID $DISK $GBSZ $VG $LV
   # Get another set
 else
    echo $AID $WWID $DISK Err  Err  Err
 fi
   shift 2
 done 
 echo
done
