ChinaUnix首页 > 精华文章 > Mail服务器 > 正文

[保留] 自制的qmail用户空间检测脚本


http://www.chinaunix.net 作者:ipod2008  发表于:2009-03-07 10:04:25
发表评论】 【查看原文】 【Mail服务器讨论区】【关闭

本人使用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 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 }')
      [email=ADDRESS=$ACCOUNT@$SUBDOMAIN]ADDRESS=$ACCOUNT@$SUBDOMAIN[/email] 
     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=postmaster@ata.com.cn]postmaster@ata.com.cn[/email]
To: $ADDRESS
Subject: Mail quota warning
Sir/Madam:
         How are you!
   This e-mail was automatically sent from the mail.ata.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
ATA  Information Service
Data Network Center(ShangHai/China)
[email=postmaster@XXX.com.cn]postmaster@XXX.com.cn[/email]
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 于 2008-11-26 17:02 编辑 ]



 hancang2000 回复于:2008-11-27 18:11:11

:mrgreen: 好东西 我记下了 你是强人


 lyd1999 回复于:2009-03-07 10:04:25

楼主shell功底很好。




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=1320192
转载请注明作者名及原文出处