# created 28 Mar 2003 

#

# monitor directory sizes

#


DIR=$1

[ -z "$DIR" ] && echo -e "\nDIRMON needs a search path.\nPlease enter one. [dirmon path]\n" && exit

EMAIL="user@server.com"

# send mail at this limit

WARN=10000


echo

echo Directory File Count List

echo --------------------------------------------

{

for x in `find $DIR -type d 2>/dev/null`

do

        COUNT=`ls -laA $x 2>/dev/null | wc -l`

        COUNT=`echo $COUNT`

echo -ne "$COUNT\t "

echo -e "$x"

        if [ $COUNT -gt $WARN ] 

        then

COUNT=`echo $COUNT`

echo -e "$COUNT\t exceeds the warning limit of $WARN files in $x" >>dirmon.email

        fi

done

} | sort -g

echo


if [ -f dirmon.email ]

then 

   SERVER=`uname -n | tr "[a-z]" "[A-Z]"`

   echo Large Directories:

   echo --------------------------------------------

   # sort

   cat dirmon.email | sort -g

   echo

   {

      echo "Subject: Huge Directory on $SERVER"

      echo

      echo Large Directories:

      echo --------------------------------------------

      cat dirmon.email | sort -g

      echo

      echo The files in these directories should be archived, or deleted.

   } | /usr/sbin/sendmail -ONoRecipientAction=add-to -fdirmon -oi "$EMAIL"

   rm dirmon.email >/dev/null 2>&1

fi