[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can anybody help on quota management



On Wed, Mar 27, 2002 at 06:51:01PM +0530, Suresh wrote:
> Hello
> 
> i have installed qmail-1.03 with the pgsql patch.Everything is working
> fine,though i am a little confused about the quota system.Is ther a way
> where i can have a softquota and a hard quota for each user ,so that when
> the user reached ..let us say 80% of his hardquota ..he het a warning.
> Is this possible?
Currently not from within qmail-sql, but you can run the following script
from a daily cronjob (it's written for pgsql, but a similar script will
work with mysql).

Regards,
Michael.


#!/bin/bash
IFS='|'
readpass=XXXXXXX
writepass=YYYYYYY

export QMAILUSER='do-not-reply'
echo $readpass | psql -d userdb -U userconsult --pset format=unaligned --pset \
tuples_only  -c "select login,virtual_host,home,hardquota from passwd" | \
while read login virtual_host home hardquota ; do
  if [ "foo$hardquota" == "foo" ] ; then :
  elif [ $hardquota -eq 0 ] ; then :
  else
     realspace=`du -ks $home | cut -f1`
     let softquota=80*hardquota/100
     if [ $realspace -ge $softquota -a $realspace -lt $hardquota ] ; then
       mail $login@$virtual_host -s "Quota Warning" << EOF
Dear,

You're currently using $realspace kb on the mailserver. We'd like to
remind you that your mailbox can only contain $hardquota kb. To prevent
problems with your mailbox, we'd like to ask you to remove your read mail.

Regards,
BOFH.
EOF
     elif [ $realspace -ge $hardquota ] ; then
       echo $writepass | psql -d userdb -U usermgr -q -c "update passwd set \
 hardquota=0 where login='$login' and virtual_host='$virtual_host'"
       mail $login@$virtual_host -s "Quota Exceeded" << EOF
Dear,

You're currently using $realspace kb on the mailserver. We'd like to
remind you that your mailbox can only contain $hardquota kb. You will
not receive any new mail until you clean your mailbox by removing your
read mails.

Regards,
BOFH
EOF
       sleep 5
       echo $writepass | psql -d userdb -U usermgr -q -c "update passwd set \
 hardquota='$hardquota' where login='$login' and virtual_host='$virtual_host'"
     fi
  fi
done