ipod2008 发表于 2008-11-26 16:01

自制的qmail用户空间检测脚本

本人使用qmail时间不长,发现vpopmail 的空间检测还不完善,一次给客户做项目,刚好有需求就写了这个脚本

结合Crontab使用效果还可以,有兴趣的网友可以试试,欢迎回馈顶贴!!:mrgreen:

#!/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 2008Firstrelease   by Li Ming
# Thu May 22 2008Second release   by Li Ming
# Fri May 23 2008Thirdrelease   by Li Ming
# Fri July 4 2008Fourth release   by Li Ming
# Mon July 7 2008Fiveth release   by Li Ming
# Mon July 14 2008Sixth   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: postmaster@xxx.com.cn
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
xxxInformation Service
Data Network Center(ShangHai/China)
postmaster@XXX.com.cn
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 编辑 ]

hancang2000 发表于 2008-11-27 18:11

lyd1999 发表于 2009-03-07 10:04

楼主shell功底很好。

ipod2008 发表于 2013-09-25 13:32

好多年前的帖子   自己回来看看
页: [1]
查看完整版本: 自制的qmail用户空间检测脚本