On Mon, 2 Oct 2017, Keith Lofstrom wrote:

After a mail transfer failure (stemming from a subtle DNS
misconfiguration), I realized I have no automated tools to keep track of
the health of the incoming mail processes.

Keith,

  On my server logwatch sends me a daily e-mail message summarizing all
systems. The postfix log is extensive and shows me any configuration or
other errors I've made or that others have made. Right after that runs
pflogsumm runs (attached, but stripped on the mail list's copy). Rather than
waiting 42 hours to fix something you'll get a daily view of what happed the
day before.

Rich
#!/bin/sh
#
# /etc/cron.daily/1pflogsumm
#
# This file is run on a daily basis to analyse your mail logs.
#
# The file is named "1pflogsumm" to ensure that it is run before logrotate
# when the /var/log/maillog files are rotated.
#
# More information at http://jimsun.linxnet.com/postfix_contrib.html
#
# uncomment the next line to completely disable the daily cronjob
# exit 0

# below added by RBS to try to find why script sometimes does not run
#set -x  > log_error.txt 2>&1

# Default location of the log file, if not learnt from LOGFILE
[ -z "${LOGFILE}" ] && [ -f /var/log/maillog ] && LOGFILE=/var/log/maillog

EXECUTABLE=/usr/local/bin/pflogsumm
TMPDIR=/etc/postfix     # default directory for temporary executable, better 
than /tmp
TMPEXE=pfls.tmp.$$      # name of executable if Date::Calc module not available

#OPTIONS="-d today --verp_mung=2 --problems_first --iso_date_time  -q -u 10 -h 
10"
OPTIONS="-d yesterday --verp_mung=2 --problems_first --iso_date_time  -q -u 10 
-h 10"
SUBJECT="`hostname` Daily Mail Report for `LC_TIME=C date +\"%A, %d %B %Y\"`"
# Send report to $REPORT_TO if defined, or postmaster@"hostname" otherwise
[ -z "${REPORT_TO}" ] && REPORT_TO="rshep...@appl-ecosys.com"
SENDMAIL=/usr/sbin/sendmail
SENDMAIL_OPTS="-oi -t -v"
POSTFIX=/usr/sbin/postfix

# Clean up when done or when aborting.
trap "test -r ${TMPDIR}/${TMPEXE} && rm -f ${TMPDIR}/${TMPEXE}" 0 1 2 3 15 

# uncomment the next line to disable retrieval of mail statistics
# exit 0

# Check mail log file exists or exit
[ ! -r "${LOGFILE}" ] && [ -r /var/log/maillog ] && LOGFILE=/var/log/maillog
[ ! -r "${LOGFILE}" ] && { echo "$0: Can not find a readable mail log file - 
exiting"; exit 1; }

# if we are not root, use a different TMPDIR
[ `id -u` = 0 ] || TMPDIR=/tmp

# Check pflogsumm.pl exists and exclude the use of Perl's Date::Calc module if 
it is not available
[ -r ${EXECUTABLE} ] || { echo "$0: ${EXECUTABLE} not found - exiting"; exit 1; 
}
[ -d ${TMPDIR} ] || { echo "$0: ${TMPDIR} is not a directory - exiting"; exit 
1; }
perl -e 'use Date::Calc;' 2>/dev/null || {
    sed -e '/# ---Begin:/,/# ---End:/d' < ${EXECUTABLE} > ${TMPDIR}/${TMPEXE}
    chmod u=rx,go= ${TMPDIR}/${TMPEXE} || echo "$0: warning - unable to set 
permissions on ${TMPDIR}/${TMPEXE}"
    EXECUTABLE=${TMPDIR}/${TMPEXE}
}
 
# Ensure the ${EXECUTABLE} and sendmail binaries exist before proceeding
[ -x ${EXECUTABLE} ] || { echo "$0: ${EXECUTABLE} not executable - exiting"; 
exit 1; }
[ -x ${SENDMAIL} ] || { echo "$0: ${SENDMAIL} not found or not executable - 
exiting"; exit 1; }
(
cat <<EOF
To: ${REPORT_TO}
Subject: ${SUBJECT}

Report based on information in ${LOGFILE}
EOF

LC_TIME=C ${EXECUTABLE} ${OPTIONS} ${LOGFILE} 2>/dev/null
echo "Report ended with status: $?" ) | ${SENDMAIL} ${SENDMAIL_OPTS}
_______________________________________________
PLUG mailing list
PLUG@lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to