#!/bin/sh # check_procmail - check for errors in procmail "from" file # Show any lines that don't look like one of these lines: # # From jpeek@jpeek.com Sun Jan 11 00:02:01 1998 # Subject: MH PostScript download log # Folder: /usr/bin/gzip >>/u/jpeek/procmail/mail.gz 8064 # # Show unique errors that weren't shown last time. # # Usage (typically from a cron job): # check_procmail address # where "address" is the email address where changes should be mailed # # Installation: # - At top of script, set the current directory for the tracking files # and check that values of variables $logfile and $mailer are okay. # - In the tracking files directory, create an empty file for $last_errors: # touch check_procmail.lasterrs # This old script is in the public domain. Do what you want with it. # Use at your own risk. I'd appreciate email about bugs and enhancements. # # Jerry Peek, jpeek@jpeek.com cd $HOME/lib/at_cron || exit 1 # holds tracking files (abort if missing) good_log_lines='^(From | [Ss][Uu][Bb][Jj][Ee][Cc][Tt]: | Folder: .*[0-9]+)$' last_errors=check_procmail.lasterrs # previous log logfile=$HOME/procmail/from # procmail's log file mailer=/usr/bin/mail # mail program with -s "subject" option mailto=${*?} # mail to this address (abort if missing) tempa=/tmp/CK_PMa$$ tempb=/tmp/CK_PMb$$ tempc=/tmp/CK_PMc$$ trap 'rm -f $tempa $tempb $tempc; exit' 0 1 2 15 # removes temp files on exit umask 77 # makes temp files readable by owner only # Find all log lines that don't match $good_log_lines: egrep -v "$good_log_lines" $logfile | sort -u > $tempa # If any differences, email them and update the $last_errors tracking file: diff $last_errors $tempa > $tempb || { mv $last_errors ${last_errors}.old cp $tempa $last_errors # diff may output only "<" lines if $logfile was replaced or truncated. # So don't show them; only show ">" lines that "diff" showed to be new: grep "^>" $tempb > $tempc if [ -s $tempc ] then $mailer -s "Procmail errors? Check '$logfile' file" $mailto < $tempc fi }