On Tue, 21 Apr 2009, chris (fool) mccraw wrote: > can we have the script itself, too?
Of course! I thought I had posted that earlier, but now realize no one would save it. #!/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. # # The file is also flagged by rpm as a configuration file, so if you modify # it, further upgrades to pflogusmm will not be overwriten. # # 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 [ -z "${LOGFILE}" ] && [ -f /var/log/mail.log ] && LOGFILE=/var/log/mail.log 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="--verp_mung=2 --problems_first --iso_date_time -q -u 10 -h 10 -d yesterday" OPTIONS="--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="[email protected]" SENDMAIL=/usr/sbin/sendmail SENDMAIL_OPTS="-oi -t" 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/mail/info ] && LOGFILE=/var/log/mail/info [ ! -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 # Perl is giving warnings on rh8 when Date::Calc is not installed. This 'hides' # them but I'd like to solve this properly once I determina the cause. LC_TIME=C ${EXECUTABLE} ${OPTIONS} ${LOGFILE} 2>/dev/null echo "Report ended with status: $?" ) | ${SENDMAIL} ${SENDMAIL_OPTS} _______________________________________________ PLUG mailing list [email protected] http://lists.pdxlinux.org/mailman/listinfo/plug
