This is a continuation of my previous thread on why the mail log summary
script fails to run. It didn't all last week while I was away and still
doesn't run.

   The context: The actual perl script, /usr/local/bin/pflogsumm, installed
without the .pl extension, runs without error when invoked from the command
line by root. The shell script that is supposed to call that script and mail
the results to me is called /etc/cron.daily/1pflogsumm. The output of this
is the error log called by the 'set -x' command, although it does not write
that to the designated filename, but to stdout. I copied that to a file so I
can show you the results.

   /etc/cron.daily/1pflogsumm has 67 lines:

#!/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

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"
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/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

   The output of the error log is:

+ '[' -z '' ']'
+ '[' -f /var/log/maillog ']'
+ LOGFILE=/var/log/maillog
+ EXECUTABLE=/usr/local/bin/pflogsumm
+ TMPDIR=/etc/postfix
+ TMPEXE=pfls.tmp.18919
+ OPTIONS='--verp_mung=2 --problems_first --iso_date_time  -q -u 10 -h 10'
++ hostname
++ LC_TIME=C
++ date '+%A, %d %B %Y'
+ SUBJECT='salmo Daily Mail Report for Wednesday, 20 May 2009'
+ '[' -z '' ']'
+ [email protected]
+ SENDMAIL=/usr/sbin/sendmail
+ SENDMAIL_OPTS='-oi -t'
+ POSTFIX=/usr/sbin/postfix
+ trap 'test -r /etc/postfix/pfls.tmp.18919 && rm -f
/etc/postfix/pfls.tmp.18919' 0 1 2 3 15
+ '[' '!' -r /var/log/maillog ']'
+ '[' '!' -r /var/log/maillog ']'
++ id -u
+ '[' 0 = 0 ']'
+ '[' -r /usr/local/bin/pflogsumm ']'
+ '[' -d /etc/postfix ']'
+ perl -e 'use Date::Calc;'
+ '[' -x /usr/local/bin/pflogsumm ']'
+ '[' -x /usr/sbin/sendmail ']'
./1pflogsumm: line 68: syntax error: unexpected end of file
+ test -r /etc/postfix/pfls.tmp.18919

   The syntax error is on the line following the last line of the script. My
naive understanding of the script is that /etc/postfix/pfls.tmp.xxxxx is the
filename only if Date::Calc is _not_ installed, yet the latest version (5.4)
is installed here.

   Obviously (to me, at least) the reason the results of 1pflogsumm are not
mailed to me is that the script terminates abnormally, but I fail to see why
that is.

   We have an elite group of highly experienced SysAdmins here so I believe
that the reason will be more visible to one of you than it is to me. The
problem is not the perl script, but the calling shell script.

TIA,

Rich
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to