Scripts for users who use too much space..

Steven M. Klass plug-discuss@lists.PLUG.phoenix.az.us
Wed, 30 May 2001 07:47:26 -0700


Thanks Rusty,

	Here is what I ended up with..  Thanks for the ideas.

#!/bin/bash
# 2001-05-29
# Find the fat files and email people to get rid of them.
 
FATDIR=/home                        #Where do you want to look
FATSIZE=100000b                     #Minimum size in bytes for files to look 
for
ADMINEML=sklass@andigilog.com       #Admins Email
ADMIN="Steven Klass $ADMINEML"      #Admins Name
 
MAILCMD=/var/qmail/bin/qmail-inject #Actual Mail command
TEMPDIR=/tmp                        #Where do you want to store the data
TEMPFILE=DiskHog                    #File name of the data
 
DATE=`/bin/date`
 
#Start the email to the admin..
 
echo To:$ADMINEML > $TEMPDIR/$TEMPFILE.ADM.$$
echo Subject: Space Hog Report $DATE >> $TEMPDIR/$TEMPFILE.ADM.$$
echo >> $TEMPDIR/$TEMPFILE.ADM.$$
echo The following people were sent notices for having fat files: >> 
$TEMPDIR/$TEMPFILE.ADM.$$
 
#Find the files
find $FATDIR -size +$FATSIZE -xdev -printf '%u\t%b\t%AD\t%h/%fd\n' | sort > 
$TEMPDIR/$TEMPFILE.$$
 
#For each user email them and add there name to the admin list
for u in `awk '{print $1}' $TEMPDIR/$TEMPFILE.$$ |sort | uniq ` ; do
  # Send the email to the user
  if [ "$u" != "root" ] ; then
    echo To:$u > $TEMPDIR/$TEMPFILE.$u.$$
    echo Subject: Space hog alert!! >> $TEMPDIR/$TEMPFILE.$u.$$
    echo Dearest Spacehog $u >> $TEMPDIR/$TEMPFILE.$u.$$
    echo >> $TEMPDIR/$TEMPFILE.$u.$$
    echo A recent scan on $DATE showed that you have some fat files that need 
to be deleted >> $TEMPDIR/$TEMPFILE.$u.$$
    echo Please contact $ADMIN if you do not understand this message >> 
$TEMPDIR/$TEMPFILE.$u.$$
    echo >> $TEMPDIR/$TEMPFILE.$u.$$
    grep $u $TEMPDIR/$TEMPFILE.$$ | sort -g -k2 -r >> $TEMPDIR/$TEMPFILE.$u.$$
    echo >> $TEMPDIR/$TEMPFILE.$u.$$
    echo Remember W: = /home/ShProj and P: = /home/user >> 
$TEMPDIR/$TEMPFILE.$u.$$
    echo >> $TEMPDIR/$TEMPFILE.$u.$$
    echo Ciao >> $TEMPDIR/$TEMPFILE.$u.$$
    echo "  The Space Hog..">> $TEMPDIR/$TEMPFILE.$u.$$
    cat $TEMPDIR/$TEMPFILE.$u.$$ | $MAILCMD
    rm $TEMPDIR/$TEMPFILE.$u.$$
    echo "     $u"  >> $TEMPDIR/$TEMPFILE.ADM.$$
  fi
done
#Give the admin a usage stat for the fatdir in question
echo >> $TEMPDIR/$TEMPFILE.ADM.$$
echo Disk Usage Stats: >> $TEMPDIR/$TEMPFILE.ADM.$$
echo >> $TEMPDIR/$TEMPFILE.ADM.$$
echo FileSystem Size Used Avail %Use Mounted On >> $TEMPDIR/$TEMPFILE.ADM.$$
echo `/bin/df --human $FATDIR | grep home`  >> $TEMPDIR/$TEMPFILE.ADM.$$
echo >> $TEMPDIR/$TEMPFILE.ADM.$$
echo Ciao >> $TEMPDIR/$TEMPFILE.ADM.$$
cat $TEMPDIR/$TEMPFILE.ADM.$$ | $MAILCMD
rm $TEMPDIR/$TEMPFILE.ADM.$$
rm $TEMPDIR/$TEMPFILE.$$

-- 

Steven M. Klass
Physical Design Engineering Manager

Andigilog Inc.
7404 W. Detroit Street, Suite 100
Chandler, AZ 85226
Ph: 480-940-6200 ext. 18
Fax: 480-940-4255

sklass@andigilog.com
http://www.andigilog.com