Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38797
  • 博文数量: 8
  • 博客积分: 190
  • 博客等级: 入伍新兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-18 15:58
文章分类

全部博文(8)

文章存档

2012年(2)

2011年(6)

我的朋友

分类: Python/Ruby

2011-12-19 08:47:06

#!/bin/bash

sys=`uname`
if [ "$sys" = "Linux" ];then
    . ${HOME}/.bash_profile
else
    . ${HOME}/.profile
fi

ALL_USER=/tmp/user.list
INFO_FILE=/tmp/uses_all.list
SEND_MAILa=/tmp/sendmail01.list
SEND_MAILb=/tmp/sendmail02.list
MAIL=/tmp/mail.list
LOG_FILE=/var/log/tmailer.log

dateStr=`date --date "1 days ago" +"%b %d"|sed 's/0/ /1'`
DEFDOMAIN=`uapi gacf | grep tmailerDefaultDomainName | awk '{print $2}'`
STMPHOSTNAME=`uapi gacf | grep tmailerSmtpHostname | awk '{print $2}'`
uapi -l gaa |grep -v admin |grep -v wiki|grep -v spam|grep -v ham  > $ALL_USER

for USER in $(cat $ALL_USER | awk '{print $1}')
do
     Num=0
     grep "$dateStr" $LOG_FILE |grep $USER| grep from= |awk '{print $6}'> $INFO_FILE
   
    for IDLIST in $(cat $INFO_FILE | awk '{print $1}')
        do
               AAA=`grep $IDLIST $LOG_FILE | grep to= | grep -v $DEFDOMAIN |wc -l`
               AAA=`expr $Num + $AAA`
               Num=$AAA
        done
 
        if [ $Num -gt 500 ];then
        echo "$USER     $Num" >> $SEND_MAILa
        uapi ma $USER tmailerAccountStatus closed
        mysql -NB -e "use treemana;update mailbox set current_mode='closed' where  email='$USER';"

        else
                echo "$USER     $Num" >> $SEND_MAILb
        fi
done
     
if [ -s $SEND_MAILa ];then
           cat $SEND_MAILa |awk '{print $1,($2)}'|sort -rgk2 >$MAIL
           /opt/tmailer/bin/sendmail admin@$DEFDOMAIN admin@$DEFDOMAIN  "More than 500 messages" $MAIL  $STMPHOSTNAME
           cat $MAIL
           rm -f $SEND_MAILa
        else
                cat $SEND_MAILb |awk '{print $1,($2)}'|sort -rgk2| head -n5 >$MAIL
                /opt/tmailer/bin/sendmail admin@$DEFDOMAIN admin@$DEFDOMAIN  "The 5 largest volume of mail" $MAIL $STMPHOSTNAME
                cat $MAIL
                rm -f $SEND_MAILb
        fi

chown -fR tmailer:tmailer /tmp/user.list
chown -fR tmailer:tmailer /tmp/uses_all.list
阅读(1479) | 评论(0) | 转发(0) |
0

上一篇:Shell 定时备份日志文件

下一篇:rpm 的使用

给主人留下些什么吧!~~