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

Re: can anybody help on quota management



Hello,

I think this will do the trick for mysql.
i didnt test it.

Greetings,

Michiel

--

#!/bin/bash
IFS='|'
readpass=XXXXXXX
writepass=YYYYYYY
database=ZZZZZZ
export QMAILUSER='do-not-reply'
mysql $database --table --skip-column-names --raw --silent --password="$readpass" -e "select login,virtual_host,home.hardquota from passwd" | sed -e 's/ //g' |egrep '^\|'
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 | mysql $database --password="$readpass" -e "update passwd set \
       hardquota='$hardquota' where login='$login' and virtual_host='$virtual_host'"
     fi
  fi
done

---

Michiel Van Opstal

Mind Linux Solutions NV
Vaartkom 11
B-3000 Leuven, Belgium
Main Tel: +32 (0)16 309 666
Main Fax: +32 (0)16 309 644
GSM: +32 (0)478 504 403
-----------------------------------------------
Gnupg public key at http://thev0ke.be/public.gpg