本人使用qmail時(shí)間不長(zhǎng),發(fā)現(xiàn)vpopmail 的空間檢測(cè)還不完善,,一次給客戶做項(xiàng)目,剛好有需求就寫了這個(gè)腳本 結(jié)合Crontab使用效果還可以,,有興趣的網(wǎng)友可以試試,歡迎回饋頂貼??! #!/bin/sh # Name : checkquota.sh # Deviser: Li Ming # Date : Fri May 16 2008 # Purpose: Quota Warning Mail # Use : chmod u+x checkquota.sh Unifies the crontab automatic movement once every day ! # History: # Fri May 16 2008 First release by Li Ming # Thu May 22 2008 Second release by Li Ming # Fri May 23 2008 Third release by Li Ming # Fri July 4 2008 Fourth release by Li Ming # Mon July 7 2008 Fiveth release by Li Ming # Mon July 14 2008 Sixth release by Li Ming PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin: export PATH #set -x DIR1="/usr/src" DIR2="/home/vpopmail/domains" DATE=`date '+%F %H:%M'` Lockfile=$DIR1/checkquota.lock if [ -f "$Lockfile" ] then echo "Lock file is exist" && exit else touch $Lockfile fi if [ -f "$DIR1/maildirsize.txt" ] then rm -rf $DIR1/maildirsize.txt else echo $DATE echo Wait a while ... du -k $DIR2 | grep "Maildir$"| sort -nr | sed 's/Maildir$//g' | sed 's/\// /g' > $DIR1/maildirsize.txt fi LINE=$(wc -l $DIR1/maildirsize.txt | /bin/cut -d ' ' -f1) for line in `seq 1 $LINE` do SUBDOMAIN=$(tail -n +$line $DIR1/maildirsize.txt | head -1 | awk '{ print $5 }') ACCOUNT=`tail -n +$line $DIR1/maildirsize.txt | head -1 | awk '{ print $NF }'` USED=$(tail -n +$line $DIR1/maildirsize.txt | head -1 | awk '{ print $1 }') ADDRESS=$ACCOUNT@$SUBDOMAIN]ADDRESS=$ACCOUNT@$SUBDOMAIN QUOTA=`/home/vpopmail/bin/vuserinfo $ADDRESS|tail -4|head -1|awk '{ print $2 }'|sed 's/S,/ /g'|awk '{ print $1 }'|tr S " "` case "$QUOTA" in NOQUOTA) continue ;; *) QUOTA_K=$(($QUOTA/1024)) USED_1=$(($USED*10)) PER=$(($USED_1/$QUOTA_K)) limit=7 if [ $PER -ge $limit ] then echo $ADDRESS sendmail -t -oi -odb<<EOF From: [email protected] To: $ADDRESS Subject: Mail quota warning Sir/Madam: How are you! This e-mail was automatically sent from the mail.xxx.com.cn e-mail server. Your total mailbox size has exceeded 70% of the assigned quota ($QUOTA_K KB).It is $USED KB by now! If your mailbox fills,it becomes impossible to receive e-mail from other e-mail addresses. So that you can continue to receive e-mail,you need to remove some messages from your mailbox. Your e-mail address: $ADDRESS Present size: $USED KB Quota size: $QUOTA_K KB xxx Information Service Data Network Center(ShangHai/China) [email protected] DATE : `date '+%F %H:%M'` EOF fi ;; esac done rm -rf $DIR1/maildirsize.txt rm -rf $Lockfile echo THE END! `date '+%F %H:%M'` [ 本帖最后由 ipod2008 于 2009-4-12 09:39 編輯 ] |
|