INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Simple space monitor - results sorted by % used by adamf
Posted: 21 Mar 02 (Edited 21 Mar 02)

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.



#!/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

Back to UNIX Scripting FAQ Index
Back to UNIX Scripting Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close