QmailAnalog & qlogtools Qmailanalog针对qmail的日志进行一些最基本的分析,并将结果发送到你指定的位置。在我的方案中,设置qmailanalog每天晚上运行,并将结果发送给管理员。 在使用qmailanalog时,我们还将会用到qlogtools软件包。
qlogtools提供一系列分析qmail日志的工具,这些工具将文件中诲涩难懂的日志转换成便於我们阅读和能够理解的报告。当安装完成Qmailstats和Qlogtools后,我将会创建一个脚本让它每天晚上运行,并将报告发送到管理
员邮箱。这个脚本也可用到我们先前安装的qms-analog,qms-analog将会提供qmail-scanner运行状态报告。#先安装qmailanalogcd /home/pkg/
tar zxvf qmailanalog-0.70.tar.gz
cd qmailanalog-0.70patch < /home/pkg/qmailanalog-0.70.errno.patch
make && make setup check#安装qlogtoolscd /home/pkg/
tar zxvf qlogtools-3.1.tar.gz
cd qlogtools-3.1
patch < /home/pkg/qlogtools_errno.patchmake./installer#现在我们要创建一个脚本,并将它添加到cron,让其每天晚上运行并产生报告。#下面是一个可靠的脚本,它将会收集qmailanalog输出的信息并产生报告。#红色部份改成你的域名。
vi /var/qmail/bin/qmailstats#!/bin/sh
# Qmailanalog invocation script
PATH=/usr/local/qmailanalog/bin:/var/qmail/bin:/bin:/usr/bin:/usr/local/bin
QMAILSTATS="/tmp/q.$$"
EMAILMSG="/tmp/qms.$$"
umask 077
cat /var/log/qmail/* /var/log/qmail/pop3d/* /var/log/qmail/pop3ds/* /var/log/qmail/smtpd/* | tai64n2tai | awk '{$1=substr($1,1,index($1,".")+6);print}' | matchup > $QMAILSTATS 5>/dev/nullDATE=`date +'%D'`echo "To:
[email protected]" > $EMAILMSG
echo "From:
[email protected]" >> $EMAILMSG
echo "Subject: Nightly Qmail Stats Report for $DATE" >> $EMAILMSG
echo "" >> $EMAILMSG
echo "" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
zoverall < $QMAILSTATS >> $EMAILMSG
echo "" >> $EMAILMSG
echo "" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
zfailures < $QMAILSTATS >> $EMAILMSG
echo "" >> $EMAILMSG
echo "" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
zdeferrals < $QMAILSTATS >> $EMAILMSG
echo "" >> $EMAILMSG
echo "" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~ L a s t 2 4 H o u r s ~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
cat /var/spool/qmailscan/qms-events.log | qms-analog 24 >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A l l R e c o r d s ~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $EMAILMSG
cat /var/spool/qmailscan/qms-events.log | qms-analog 0 >> $EMAILMSG
cat $EMAILMSG | qmail-injectrm -f $QMAILSTATS
rm -f $EMAILMSG
#设置此脚本可执行chmod 750 /var/qmail/bin/qmailstats#现在,让我们运行脚本/var/qmail/bin/qmailstats#确认你的管理员邮箱,你将会收到一份非常详尽的报告。#如果测试运行正常,那就加入cron让其每天早上3点运行。crontab -e
0 3 * * * /var/qmail/bin/qmailstats 1>/dev/null 2>/dev/null
本文地址:http://com.8s8s.com/it/it32013.htm