#!/bin/bash # weberrors - Scans through an Apache error_log file and reports the # most important errors, then lists additional entries. setglobal temp = ""/tmp/$[basename $0].$Pid"" # The following three lines will need to be customized for your own # installation for this script to work best. setglobal htdocs = '"/usr/local/etc/httpd/htdocs/'" setglobal myhome = '"/usr/home/taylor/'" setglobal cgibin = '"/usr/local/etc/httpd/cgi-bin/'" setglobal sedstr = ""s/^/ /g;s|$htdocs|[htdocs] |;s|$myhome|[homedir] |;s|$cgibin|[cgi-bin] |"" setglobal screen = '"(File does not exist|Invalid error redirect|premature EOF|Premature end of script|script not found)'" setglobal length = '5' # entries per category to display proc checkfor { grep "$(2):" $1 | awk '{print $NF}' |\ sort | uniq -c | sort -rn | head -$length | sed $sedstr > $temp if test $[wc -l < $temp] -gt 0 { echo "" echo "$2 errors:" cat $temp } } trap "$[which rm] -f $temp" 0 if test $1 = "-l" { setglobal length = $2; shift 2 } if test $Argc -ne 1 -o ! -r $1 { echo "Usage: $[basename $0] [-l len] error_log" > !2 exit 1 } echo Input file $1 has $[wc -l < $1] entries. setglobal start = $[grep -E '\[.*:.*:.*\]' $1 | head -1 | awk '{print $1" "$2" "$3" "$4" "$5 }] setglobal end = $[grep -E '\[.*:.*:.*\]' $1 | tail -1 | awk '{print $1" "$2" "$3" "$4" "$5 }] /bin/echo -n "Entries from $start to $end" echo "" ### Check for various common and well-known errors: checkfor $1 "File does not exist" checkfor $1 "Invalid error redirection directive" checkfor $1 "premature EOF" checkfor $1 "script not found or unable to stat" checkfor $1 "Premature end of script headers" grep -vE $screen $1 | grep "\[error\]" | grep "\[client " | \ sed 's/\[error\]/\`/' | cut -d'`' -f2 | cut -d' ' -f4- | \ sort | uniq -c | sort -rn | sed 's/^/ /' | head -$length > $temp if test $[wc -l < $temp] -gt 0 { echo "" echo "Additional error messages in log file:" cat $temp } echo "" echo "And non-error messages occurring in the log file:" grep -vE $screen $1 | grep -v "\[error\]" | \ sort | uniq -c | sort -rn | \ sed 's/^/ /' | head -$length exit 0