Bug#476541: exim4-base: please handle nearly-empty logfile in daily cronjob stats

Justin Pryzby justinpryzby at users.sourceforge.net
Mon Apr 21 01:30:33 UTC 2008


On Sun, Apr 20, 2008 at 10:41:10PM +0200, Marc Haber wrote:
> On Sun, Apr 20, 2008 at 04:21:38PM -0400, Justin Pryzby wrote:
> > On Sun, Apr 20, 2008 at 09:34:04PM +0200, Marc Haber wrote:
> > > On Thu, Apr 17, 2008 at 08:41:52AM -0400, Justin Pryzby wrote:
> > > > That's probably due to very low mail volume on this laptop machine, in
> > > > combination with an earlier logfile rotation.

> +    if [ "$(< /var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" | wc -l)" -gt "0" ]; then

> (please apply manually, I had to zap a hunk of irrelevant changes from
> the output of svn diff)
Hi Marc

I rewrote your patch to use a tempfile instead to reduce code
duplication.  I used the [ -s "$t" ] || echo .. >"$t" instead of an
if [ -s "$t" ]; then cat "$t"; else echo ..; fi |mail since the former
has better error handling than the pipe (f.e. if cat manages to have
an IO error).

I had to discard stderr, which I'm not entirely happy with, but it
seems unavoidable without changing eximstats since the message we're
trying to avoid goes to stderr and sets $? -ne 0.  So the only
(poor) possibility is to test the file content against a known string.

Otherwise this is tested to work okay.
-------------- next part --------------
--- ./exim4-base	2008-04-20 21:20:20.000000000 -0400
+++ /etc/cron.daily/exim4-base	2008-04-20 21:24:22.000000000 -0400
@@ -34,10 +34,17 @@
 # Patches for more sophisticated processing are appreciated via the
 # Debian BTS.
 
+E4BCD_MAINLOG_NOISE="^[[:digit:][:space:]:-]\{20\}\(\(Start\|End\) queue run: pid=[[:digit:]]\+\|exim [[:digit:]\.]\+ daemon started: pid=[[:digit:]]\+, .*\)$"
 if [ -n "$E4BCD_DAILY_REPORT_TO" ]; then
   if [ -x "$(command -v eximstats)" ]; then
-    eximstats </var/log/exim4/mainlog \
-                | mail $E4BCD_DAILY_REPORT_TO -s"$(hostname --fqdn) Daily email activity report"
+    t=`tempfile`
+    trap 'rm -fv -- "$t"' EXIT
+    </var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" |
+      eximstats $E4BCD_DAILY_REPORT_OPTIONS >"$t" 2>/dev/null
+    [ -s "$t" ] || echo "no mail activity in this interval" >"$t"
+    <"$t" mail $E4BCD_DAILY_REPORT_TO -s"$(hostname --fqdn) Daily email activity report" 
+    rm -f "$t"
+    trap - EXIT
   fi
 fi
 


More information about the Pkg-exim4-maintainers mailing list