postfix log简要整理

前端之家收集整理的这篇文章主要介绍了postfix log简要整理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash

#-------------------------------------------------------
#TITLE:		Postfix Mail Log Handle
#AUTHOR:	HankZhou
#TIME:		2013/07/17
#VERSION:	0.5V
#-------------------------------------------------------

#To determine whether a file exists
if [ ! -e $1 ]
then 
  printf "$1 No such file or directory\n\r"
  exit 0
fi

dirName="maillog"$(date +%y%m%d%H%M%S)

#To determine whether a directory exists
if [  -d $dirName ]
then
    printf "Folder already exists\n\r"
    exit 0
fi

mkdir $dirName

#Sented File handling
cat $1 | \
awk '{if(match($12,/^status=sent$/)) 
    {mat=match($7,/[a-zA-Z0-9\_]+\@[a-zA-Z0-9\_\.]/); 
    lenMatch=length($7); 
    matched=substr($7,5,lenMatch-6); 
    timeOri=$1" "$2" "$3; 
    cmd="date \""timeOri"\" \"+%Y/%m/%d %T \""; 
    cmd|getline time;
    lenTime=length(time); 
    timeH=substr(time,lenTime-1); 
    print timeH","matched ",Message accepted"}}' | \
awk 'BEGIN{FS=OFS=","} 
    {a[$2]++;a[$0]++; 
    if(a[$2]<2) 
        {print $0}}' \
>./$dirName/sented.csv

#calculate number of lines
lines=$(awk '{b++;}END{print b}' ./$dirName/sented.csv)
printf "**\n\rSented mail has been generated.\n\r"
printf "Totle of $lines lines\n\r"

#Error File handling
cat $1 | \
awk '{if(match($12,/^status=(deferred|bounced|expired)$/)) 
    {mat=match($7,lenMatch-6); 
    timeOri=$1" "$2" "$3; 
    cmd="date -d \""timeOri"\" \"+%Y/%m/%d %T \""; 
    cmd|getline time; 
    lenTime=length(time); 
    timeH=substr(time,lenTime-1); 
    printf timeH","matched",";
    printf substr($12,8);
    for (i=13;i<=NF;i++){printf $i" "};
    print "\n";}}' | \
awk 'BEGIN{FS=OFS=","} 
    {a[$2]++;a[$0]++; 
    if(a[$2]<2) 
        {print $0}}' \
>./$dirName/ErrorMail.csv


lines=$(awk '{b++;}END{print b}' ./$dirName/ErrorMail.csv)
printf "**\n\rError mail  has been generated.\n\r"
printf "Totle of $lines lines\n\r"

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章