#!/bin/ksh # # 21/07/2003, Thomas Sluyter, UNIX Support # Script develloped by Sun Team (Thomas Sluyter) in his role as Storage Administrator # for SMG Team. # # Script will determine the amount of EMC disk space assigned to a Sun Solaris host, # along with the amount of this space used up by volumes. Per file system volume # (raw database volumes are excluded) the script will also list the amount of free # space. # # A method to determine the usage on a raw database device also needs to be determined. # # Initial clean up, in case this script ran earlier with a failure rm /tmp/diskfree.* >/dev/null 2>&1 # Build list of controlers LOCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep -i "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | sed -e 's/c//' | tr -d '\n'` EMCCONTS=`vxdmpadm listctlr all | grep -v "=" | grep -i "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | tr -s '\n' ' ' | awk '{print $1}'` EMCPRIM=`vxdmpadm listctlr all | grep -v "=" | grep -i "emc" | grep -v "CTLR-NAME" | awk '{print $1}' | head -1` #echo "The non-EMC disk controllers are: " $LOCCONTS #echo "The EMC disk controllers are: " $EMCCONTS # Build list of disk groups (non rootdg) echo > /tmp/diskfree.dg; vxdisk list | grep ^$EMCPRIM | awk '{print $4}' | sort -u | grep -v "-" > /tmp/diskfree.dg echo > /tmp/diskfree.unalloc; vxdisk list | grep ^$EMCPRIM | sort -u | grep "-" | grep -v "d0" | awk '{print $1}' > /tmp/diskfree.unalloc DGfree() { for DG in `cat /tmp/diskfree.dg` do echo "Disk group $DG:" if [ `vxdisk list | grep $DG | grep $EMCPRIM | wc -l` -gt "0" ] then ASSIGNED=0 for VAL in `vxprint -g $DG | grep ^dm | grep $EMCPRIM| awk '{print $5/2048}' | tr . Q | sed -e 's/Q.*//'` do ASSIGNED=`expr $ASSIGNED + $VAL` done echo "Total assigned EMC disk space: $ASSIGNED MB." else echo "No EMC disks assigned to disk group $DG!" fi if [ `vxdg -g $DG -q free | grep $EMCPRIM | wc -l` -gt "0" ] then #echo "Total free space per EMC disk: " #vxdg -g $DG free | grep $EMCPRIM | /usr/bin/nawk '{print $3 "\t" $5/2048 " MB"}' for TAG in `vxdg -g $DG free | grep $EMCPRIM | /usr/bin/awk '{print $1}' | sort -u` do FREE=0 for VAL in `vxdg -q free $TAG | /usr/bin/nawk '{print $6/2048}' | tr . Q | sed -e 's/Q.*//'` do VAL=`echo $VAL | tr . Q | sed -e 's/Q.*//'` FREE=`expr $FREE + $VAL` done DISK=`vxdg -q free $TAG | awk '{print $4}' | sort -u` echo "EMC disk $DISK has $FREE MB in free space." done else echo "No more free space for disk group $DG!" fi if [ `vxdisk list | grep $DG | grep $EMCPRIM | wc -l` -gt "0" ] then for VOL in `vxprint -g $DG | grep ^v | grep -v swap | awk '{print $2}'` do MOUNT=`mount | grep $DG | grep "\/$VOL " | awk '{print $1}'` if [ $MOUNT != "" ] then FREE=`df -k $MOUNT | grep -v Filesystem | awk '{print $4/1024}' | tr . Q | sed -e 's/Q.*//'` PRCNT=`df -k $MOUNT | grep -v Filesystem | awk '{print $5}'` echo "Filesystem $MOUNT has $FREE MB of free disk space ($PRCNT full)." fi done else echo "No EMC disks assigned to disk group $DG!" fi echo "" done } NOfree() { if [ `wc -l /tmp/diskfree.unalloc | awk '{print $1}'` -gt "0" ] then for DISK in `cat /tmp/diskfree.unalloc` do echo "$DISK is unallocated or uninitialized and available." done echo "" else echo "No unallocated or uninitialized EMC disks available!" echo "" fi } RESTRICT() { DATE=`date '+%d-%m-%y'` PLAT="Sun" NAME=`hostname` ASGN=0 USED=0 FREE=0 UNALLOC=0 # If there are no EMC disks assigned to this server ASSGN, USED and FREE will all # remain zero after the following if-loop. if [ `vxdisk list | grep $EMCPRIM | wc -l` -gt "0" ] then for VAL in `vxprint | grep ^dm | grep $EMCPRIM| awk '{print $5/2048}'| tr . Q | sed -e 's/Q.*//'` do ASGN=`expr $ASGN + $VAL` done fi # Determining total free space. # If no free space is left, USED and FREE will remain zero. if [ `vxdg -q free | grep $EMCPRIM | wc -l` -gt "0" ] then for VAL in `vxdg -q free | grep $EMCPRIM | /usr/bin/nawk '{print $6/2048}' | tr . Q | sed -e 's/Q.*//'` do FREE=`expr $FREE + $VAL` done fi USED=`expr $ASGN - $FREE` ASGN=`echo $ASGN|/usr/bin/nawk '{print $1/1024}'` USED=`echo $USED|/usr/bin/nawk '{print $1/1024}'` FREE=`echo $FREE|/usr/bin/nawk '{print $1/1024}'` UNALLOC=`wc -l /tmp/diskfree.unalloc|awk '{print $1}'` echo "$DATE\t$PLAT\t$NAME\t$ASGN\t$USED\t$FREE\t$UNALLOC" } FULL() { echo "============================================================================"; echo "" echo "EMC DISK SPACE USAGE REPORT FOR HOST `hostname`" echo ""; echo "============================================================================" echo ""; echo "" DGfree NOfree echo "============================================================================"; echo "" } case $1 in full) FULL;; *) RESTRICT;; esac # Cleanup stuff rm /tmp/diskfree.*