#!/usr/bin/bash # Modify the above line to reflect the actual location of bash on your # system, which you can determine with the command "which bash". E.g. # for Solaris 7, it may be /usr/local/bin/bash. You # will get a "not found" error message if it is incorrect. # Name: soldiskspace # Author: Sandra Henry-Stocker, ITworld.com # Modified By: Jim Cameron # Last Modified: June 28, 2006 # Version 1.1 # Obtained from: http://www.itworld.com/Comp/1375/nls_unixcalculate041223/ # Obtained on: June 28, 2006 # This script displays usable disk space on a Solaris system, but not # necessarily the totality of disk space on the system. A system with # mirrored disks, for example, will appear to have half as much disk space as # it actually contains. # This script and an explanation of how it works appears in # an article titled "Calculating overall disk space", which appeared in # "ITworld.com, Unix in the Enterprise 12/23/04" at # http://www.itworld.com/Comp/1375/nls_unixcalculate041223/ # Modifications: # 6/28/2006 Replaced "who am i" check with a "whoami" check instead, since # "who am i" will not return "root" if you have su'ed to the root account, # but "whoami" will return "root". # ---- some of the commands used by this script are privileged ---- if [ `/usr/ucb/whoami` != "root" ]; then echo Sorry, this script must be run by root exit 1 fi # calculate disk space using prtvtoc disk geometry details # ---- first, get list of disks ---- disks=( `ls /dev/rdsk/c*s2` ) total=0; # ---- how many disks? ---- sz=${#disks[*]} # ---- get disk size for each ---- n=0 echo "Disks:" while [ $n -lt $sz ] do geom=( `prtvtoc ${disks[$n]} 2>/dev/null | egrep "sector|track|cylinder" | tr -d "*" | awk '{print $1}'` ) # ---- get disk parms and calculate size ---- BperS=${geom[0]} SperT=${geom[1]} TperC=${geom[2]} SperC=${geom[3]} Cyls=${geom[4]} AccCyls=${geom[5]} if [ "$BperS" != "" ]; then size=`expr $BperS \* $SperC \* $Cyls` GB=`expr $size \/ 1024 \/ 1024 \/ 1024` echo -n " ${disks[$n]}: " echo $GB "Gbytes" total=`expr $total + $GB` fi n=`expr $n + 1` done echo " TOTAL: $total GB"