Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple space monitor - results sorted by % used

Simple space monitor - results sorted by % used

by  adamf  Posted    (Edited  )
A useful script for keeping an eye on 'busy' systems with loads of mounts. This sorts disk usage by space or inodes, and by default only lists the top 10 filesystems.

This WILL work on Solaris and NCR-UX... and SHOULD work on other OS.

Code:
#!/bin/ksh
##################################################################### 
# TITLE:     uxspace
# AUTHOR:    Adam Forrest
# DATE:      March 2002 
# USAGE:     Sorts filesystem usage by % space or inodes used
##################################################################### 

me=`basename $0`
HDR1="Unix Filesystems by Space Usage (Kb)"
HDR2="===================================="                   
HDR3="\nFilesystem                      %Used Capacity     Used     Free"
EXCLUDE_LIST="/dev/fd|/stats|/proc|filesystem"
P_HDR1="Summary of "
P_HDR2="======="
VERSION="1.0"

LIST()
{
head -10
}

USAGE()
{
echo "Usage: $me [ -l ] [ -i ] [ -v ]"
echo "Where -l   long listing"
echo "      -i   Filesystem inode details"
echo "      -v   Program version details"
exit 1
}
 
DF_CMD()
{
df -k | egrep -v -i "$EXCLUDE_LIST" | sort -n -r +4.0 -5.0| LIST | awk '{printf "%-32s %+4s %+8s %+8s %+8s\n", $6, $5, $2, $3, $4 }'
}


WHICH_OS()
{
uname -a | awk '{print $3}' | while read OS
do
  if [ $OS = 5.6 ] ; then
    INODE_DF="/usr/bin/df -oi"
  else
    INODE_DF="/usr/ucb/df -i"
  fi
done
}

while getopts flvi val 2>/dev/null
do
  case $val in
        f)      ;;
        l)      LIST()
                {
                tr " " " "
                }
                P_HDR1=""
                P_HDR2="";;
        v)      echo "This is version $VERSION of $me"
                exit 1 ;;
        i)      WHICH_OS 
                HDR1="Unix Filesystems by Inode Usage"
                HDR2="==============================="
                HDR3="\nFilesystem                      %IUsed   Iused    Ifree"
                DF_CMD()
                {
                   $INODE_DF 2>/dev/null | egrep -v -i "$EXCLUDE_LIST" |                    sort -n -r +3.0 -4.0 | LIST |                    awk '{printf "%-32s %+4s %+8s %+8s\n", $5, $4, $2, $3 }'
                }
                ;;
        v)      echo "Version 1.0";;
        *)      USAGE ;;
        esac
done
shift `expr $OPTIND - 1`

echo "\t$P_HDR1$HDR1\n\t$P_HDR2$HDR2$HDR3"
DF_CMD|LIST
echo
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top