Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- Unix Scripts Tips

Useful Links

- Bash shell HOWTO
- Bourne Shell Man Page
- C Shell Guide
- Korn Shell Resources

top20du.sh

#!/bin/ksh # # Directory analyzer (for 10.20 and higher, uses du -k capability) # # Usage: # # top20du [ <directory> [ <directories> ....] ] # # default is to use the current working directory. # # Go through each directory specified # set -u MYOS=`uname` MYREV=`uname -r | cut -f 2-3 -d .` case $MYOS in HP-UX) if [ $MYREV -lt "10.00" ] then MYPATH=/bin MYDU=/bin TEMPDIR=/usr/tmp/Top20du else MYPATH=/usr/bin MYDU=/usr/bin TEMPDIR=/var/tmp/Top20du fi ;; SunOS) MYPATH=/usr/bin MYDU=/usr/xpg4/bin TEMPDIR=/var/tmp/Top20du ;; *) MYPATH=/usr/bin MYDU=/usr/bin TEMPDIR=/var/tmp/Top20du ;; esac $MYPATH/rm -rf $TEMPDIR $MYPATH/mkdir $TEMPDIR trap "$MYPATH/rm -rf $TEMPDIR" 0 1 2 3 15 # Establish a starting directory even if omitted if [ $# -lt 1 ] then STARTDIR=$($MYPATH/pwd) else STARTDIR="$@" fi # Expand to a full path name from any relative expression # But first, use a redirection of std error to the LSERROR # file. This solves a problem in assigning STDERR from ls # to a simple variable. LSERRORS=$TEMPDIR/lserrors for DIRSPEC in $STARTDIR do $MYPATH/ls $DIRSPEC 1> /dev/null 2> $LSERRORS if [ -s $LSERRORS ] then echo echo "$DIRSPEC: $($MYPATH/cat $LSERRORS)" elif [ ! -d $DIRSPEC ] then echo echo "$DIRSPEC is not a directory" echo else DIRSPEC=$(cd $DIRSPEC;$MYPATH/pwd) echo echo "Summary of $DIRSPEC (in K-bytes, top 20):" # Tricky code: du -k (show in kbytes, not blocks) was introduced # at 11.0 and undocumented at 10.20 but not available prior to 10.20. # # For maximum portability, this code parses out the directory SIZE # and performs the math for Kbytes, then typesets the SIZE in right # justified output. The quotes " " maintain leading spaces in echo. # # For really pretty output, this code switches from Gb to Mb to Kb # for units of measure depending on the size of the directory. PREVUNITS="none" $MYDU/du -x $DIRSPEC | sort -rn | head -20 | while read SIZE DIR do if [ $SIZE -gt 1999.9 ] then if [ $SIZE -gt 1999999.9 ] then RSIZE=$(echo "scale=1 \n $SIZE/2000000.0" | bc) UNITS=Gb if [ $PREVUNITS != $UNITS ] then echo PREVUNITS=$UNITS fi else RSIZE=$(echo "scale=1 \n $SIZE/2000.0" | bc) UNITS=Mb if [ $PREVUNITS != $UNITS ] then echo PREVUNITS=$UNITS fi fi else RSIZE=$(echo "scale=1 \n $SIZE/2.0" | bc) UNITS=Kb if [ $PREVUNITS != $UNITS ] then echo PREVUNITS=$UNITS fi fi printf "%6.1f %s %s\n" $RSIZE $UNITS $DIR done fi done $MYPATH/rm -rf $TEMPDIR #### END OF SCRIPT

Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries