[wplug] Script to check mailbox size

Tom Rhodes trhodes at FreeBSD.org
Wed Aug 6 01:46:04 EDT 2008


On Tue, 5 Aug 2008 13:27:13 -0400
DK <wplug at curlynoodle.com> wrote:

> Hello Everyone:

Hey,

> 
> I recently switched my company's hosting to Pair Networks.  As part of
> the migration, I was forced to impose a quota on everyone's mailbox.
> I would like to create a script which will get the size of each
> mailbox file then send an email alerting the user if the size is ~80%
> from the quota.
> 
> Has anyone written something like this?  Or, could you point me to an
> example I can use to educate myself.

Originally designed to warn people of their disk usage because
quotas will actually prevent accepting email when a user hits
their limit.  I'm sure you could make some minor changes so it
cares more about mailboxes instead of user totals.  Written in
csh(1).


#!/bin/csh
#
# Simple space usage watching script, disk quotas are so mean in the
# horrible fact that they block all write access when enforced.  This
# script is nicer, it scans the home directories of all nonsystem 
# accounts, and emails a warning message to any user that is using
# an amount of space above the specified allowance.

# Here will will set the maximum space per home directory, my default
# is 10,000 kb, which is roughly around 10 mb.
set maxusage=10000

# Review every login name, skip the first 19 accounts though.
foreach user ( `awk -F: '{ print $1 }' /etc/passwd | tail +19` )

# Get the users home directory
set dir=`grep "^"$user":" /etc/passwd | awk -F: '{ print $6 }'`

# Find out how much disk space the home directory is using
set usage=`du -s $dir | awk '{ print $1 }'`

# Now check the space used, and compare that amount to the maxusage
# variable.
if ( $usage > $maxusage ) then

# We describe how to deal with it.  Email the user a warning message.
set subject="Pittgoth.com Warning! You are using $usage KB of disk space"
mail -s "$subject" $user < /usr/local/quota.txt

# Tell me about the violation, print the username to the current
# screen.
echo User $user is using $usage KB of disk space!

endif
end


-- 
Tom Rhodes


More information about the wplug mailing list