#!/bin/csh -f # mailwarns # ----------------------------------------------------------------------------- # Shell script to search mail log for warnings. # ----------------------------------------------------------------------------- # 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 set logfile = "/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 "Warnings in ${logfile}: " sudo grep -H -i warn ${logfile}