#!/bin/csh -f # mailerrs # ----------------------------------------------------------------------------- # Shell script to search mail log for errors and retries of the same message, # to show that they all eventually got sent. # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help option to see usage. # Assumptions: # Effects: # - Reads the mail log, prompting for sudo password and shows report. # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ------------------------------------------------------------------------------ if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [-a | mail_log_filename]" echo " -a = All mail log files" echo "Example: $0:t" echo "Example: $0:t maillog-20101114" echo "Example: $0:t 20101114 (same as maillog-20101114)" echo "Example: $0:t -a" exit 1 endif # Get and check options set option_all = "false" if ($#argv > 0 && "$1" == "-a") then set option_all = "true" shift endif # Get and check params set logfile = "maillog" if ($#argv > 0) then set logfile = $1:q shift endif if ("${option_all}" == "true") then # Current logfile last, after older ones in date order set logfile = "/var/log/maillog-* /var/log/maillog" else if (-e "/var/log/${logfile}") then set logfile = "/var/log/${logfile}" else echo "File /var/log/${logfile} not found." echo "Trying /var/log/maillog-${logfile}..." if (-e "/var/log/maillog-${logfile}") then set logfile = "/var/log/maillog-${logfile}" else echo "File /var/log/maillog-${logfile} not found." beep "Error: Unable to find specified mail log file." exit 1 endif endif # Get sudo to prompt now, if it is going to, to avoid prompt later. sudo cat /dev/null echo "Failed mail messages in ${logfile}: " sudo grep -H stat= ${logfile} | grep -v stat=Sent | wc -l foreach line (`sudo grep -H stat= ${logfile} | grep -v stat=Sent | awk -F: '{print $5}'`) echo "----------------------------------------------------------------" sudo grep -H ${line} ${logfile} echo "----------------------------------------------------------------" end