"mailstat" is a helper program, like formail, which is included in the procmail package. It automatically moves the log file you feed it to a new file by the same name plus the extension ".old", so in this case, it moves "pm.log" to "pm.log.old".
To use this conveniently, save it to a directory that is in your Unix "PATH" -- I use $HOME/bin.
#! /bin/bash #----------------------- # Save as $HOME/bin/jtest and make executable with: # $ chmod +x $HOME/bin/jtest #----------------------- # To see a line for each message as the log is purged, use this line: # mailstat $HOME/pm.log # remove the leading # to activate # To just purge the log and rely on the summary, use this line instead: mailstat $HOME/pm.log > /dev/null # This line is active # mailstat creates pm.log.old - if it's empty, that means no new mail: if [ ! -s $HOME/pm.log.old ]; then echo "Nothing new." exit 0 fi # To get a summary, scan the backed-up log with GNU grep: grep -A 2 "From " $HOME/pm.log.old | grep -v Folder echo " " # Counters are good -- the backtick trick keeps everything together # on the same line: echo `grep "From " $HOME/pm.log.old | wc -l` "messages, "\ `grep "/dev/null" $HOME/pm.log.old | wc -l` dropped # Each run destroys the .old file, so let's save one more generation # in case we want to review it in more detail later: mv $HOME/pm.log.old $HOME/pm.log.older touch $HOME/pm.log.old # zero line file = "Nothing new." message echo " "
