Chinaunix首页 | 论坛 | 博客
  • 博客访问: 395698
  • 博文数量: 74
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-21 17:34
文章分类
文章存档

2011年(1)

2010年(1)

2009年(72)

我的朋友

分类: LINUX

2009-07-21 11:42:32


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

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

#!/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 }')
     
     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<From:
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)

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 编辑 ]

 
阅读(1759) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~