lsds

The report that this script creates is used by AIX Unix administrators and end users to help determine what space has been allocated to different volume groups and logical partitions. The script uses sed and awk heavily and is able to catch if a user tries to break out of a script and cleans up the transient files put in /tmp. This script will not work for newer versions of AIX. I'll have to wait till I get another chance to work with AIX before I can update this script.
#!/bin/ksh
#*************************************************************************
# Script Name:      lsds
# Creation Date:    4/15/99
# Location:         /usr/local/bin
# Calling Routine:  NONE
# Input Parameters: NONE 
# Description:      Reports how disk space is allocated (on AIX machines)
# Change Log
# Name              Change
# ----------------- ------------------------------------------------------
# Paul McKinney     Creation
#
#*************************************************************************

trap 'rm -f /tmp/$$.tmp1 /tmp/$$.tmp2 > /dev/null; \
       echo $0 aborted.;exit 1' 1 2 15
lspv | awk ' 
	{ 
	if ($3 ~ /None/) next 
	print "lspv -l " $1 
	}' > /tmp/$$.tmp1
chmod 700 /tmp/$$.tmp1
lspv > /tmp/$$.tmp2
/tmp/$$.tmp1 >> /tmp/$$.tmp2
lsvg -o|lsvg -i -l >> /tmp/$$.tmp2
printf "%-15s" "VOL GRP"
printf "%-10s" "PHYS VOL"
printf "%-15s" "LOGICAL VOL"
printf "%-5s" "LPs"
printf "%-5s" "PPs"
printf "%-5s" "PVs"
printf "%-8s" "TYPE"
printf "%-15s\n" "MOUNT POINT"
awk < /tmp/$$.tmp2 '       BEGIN {
	tempvalue1 = ""
        hdiskname = ""
        }
	NF == 3 && ($3 !~ /None/) {
		hdvg[$1] = $3
		vghd[$3] = $1
		}
	NF == 1 { 
		tempvalue1 = $1 
		}
        NF == 7 && ($5 ~ /DISTRIBUTION/) { 
		hdiskname = substr(tempvalue1,0,length(tempvalue1)-1)
		}
	NF == 5 || NF == 4 { 
		hdlv[hdiskname ":" $1] = $1 ":" $2 ":" $3 
		} 
	NF == 10 { 
		vgname = substr(tempvalue1,0,length(tempvalue1)-1)
		}
	NF == 7 && ($5 !~ /DISTRIBUTION/) { 
		lvinfo[$1] =  $2 ":" $3 ":" $4 ":" $5 ":" $7
		}
	END 	{
		line = 1
		for (indx1 in hdvg) {
			for(indx2 in hdlv) {
				split(indx2,fields,":")
				if (fields[1] == indx1) {
					split(hdlv[indx2],fields,":")
					out_hdname[line] = indx1 # hardisk
					out_vgname[line] = hdvg[indx1] # vgname
					out_lvname[line] = fields[1] # lvname
					out_LPs[line] = fields[2] # LPs
					out_PPs[line] = fields[3] # PPs
					line++
				}
			}
		}
		for (i=1; i < line; i++) {
			tmpvar1 = lvinfo[out_lvname[i]]	
			split(tmpvar1,fields,":")
			out_lvtype[i] = fields[1] # lv type
			out_PVs[i] = fields[4] # PVs
			out_mntpt[i] = fields[5] # mount point
		}
		for (i=1; i < line; i++) {
			printf ("%-15s", out_vgname[i]) #volume group
			printf ("%-10s", out_hdname[i]) #hardisk
			printf ("%-15s", out_lvname[i]) #logical volume
			printf ("%-5d", out_LPs[i])  #LPs
			printf ("%-5d", out_PPs[i])  #PPs
			printf ("%-5d", out_PVs[i])  #PVs
			printf ("%-8s", out_lvtype[i]) #lv type
			printf ("%-15s\n", out_mntpt[i])  #mount point
		}
		} #END
	' | sort
rm /tmp/$$.tmp1 /tmp/$$.tmp2
echo
lsvg -o | sort | lsvg -i > /tmp/$$.tmp2
lspv | sort | awk ' $3 !~ /None/ { print "lspv" " " $1 } ' > /tmp/$$.tmp1
chmod 700 /tmp/$$.tmp1
/tmp/$$.tmp1 >> /tmp/$$.tmp2
awk < /tmp/$$.tmp2 ' BEGIN { printheader = 1
			printf ("%-15s", "LOGICAL VOLUME")
			printf ("%10s", "TOTAL PP")
			printf ("%9s", "FREE PP")
			printf ("%9s", "USED PP")
			printf ("%9s\n", "PP SIZE")
			 }
		/^VG STATE/ { ppsize = $6 }
		/^VOLUME GROUP/ { volgrp = $3 }
		/^VG PERMISSION/ { totalpp = $6 }
		/^MAX LVs:/ { freepp = $6 } 
		/^LVs:/ { usedpp = $5 
				printf ("%-15s", volgrp)
				printf ("%10d", totalpp)
				printf ("%9d", freepp)
				printf ("%9d", usedpp)
				printf ("%7d%2s\n", ppsize, "MB")
			}
		/^PHYSICAL VOLUME/ { physvol = $3
				if (printheader) {
					print "\r"
					printf ("%-15s", "PHYSICAL VOLUME")
					printf ("%10s", "TOTAL PP")
					printf ("%9s", "FREE PP")
					printf ("%9s", "USED PP")
					printf ("%9s\n", "PP SIZE")
					printheader = 0
				}
				}
		/^PP SIZE:/ { ppsize = $3 }
		/^TOTAL PPs:/ { totalpp = $3 }
		/^FREE PPs:/ { freepp = $3 }
		/^USED PPs:/ { usedpp = $3 
				printf ("%-15s", physvol)
				printf ("%10d", totalpp)
				printf ("%9d", freepp)
				printf ("%9d", usedpp)
				printf ("%7d%2s\n", ppsize, "MB")
				} '
rm /tmp/$$.tmp1 /tmp/$$.tmp2