The following bash script sends an email with the PHP error logs for each day.
#!/bin/bash
# phperrlog v1.0
# by vladimir prelovac http://www.prelovac.com/vladimir/
#
# parse error logs on your server and send you daily updates to email
# configure options
EMAIL="tech@domain.com"
WORKDIR="/var/scripts"
TAIL=50 # number of entries to send
# IGNORE="/backup" # path to ignore
# script starts 'ere
cd $WORKDIR
rm phperrlog.txt 2>/dev/null
LIST=$(ls /var/log/apache2/*-error.log)
today=$(date +%Y-%m-%d)
for i in $LIST
do
if [ -f $i ]; then
time=$(date -r $i +%F)
if [ "$time" == "$today" ]; then
echo $i >>phperrlog.txt
echo "---------------------------------" >>phperrlog.txt
tail -n $TAIL $i >>phperrlog.txt
echo -e "\n\n\n\n" >>phperrlog.txt
fi
fi
done
if [ -f phperrlog.txt ]; then
mail -s "PHPERRORLOG SCRIPT: server error logs - $today" $EMAIL < phperrlog.txt
fi
How can I modify this script so that it excludes all errors similar to this:
[Thu Aug 02 10:54:33 2012] [error] [client 12.345.67.89] Directory
index forbidden by Options directive:
/var/www/domain/public/templates/img/[Thu Aug 02 11:25:35 2012] [error] [client 12.345.67.89] client denied
by server configuration:
/var/www/domain/public/templates/sidebar.tpl
I am more interested in the:
- PHP Notice/Warning/Fatal Errors
- File does not exist
grepcan read patterns from a fileIn your case you have to decide whether you want to use a whitelist (list of patterns you want to see in your report) or blacklist (list of pattern you don’t want to see). Once you have collected the relevant patterns replace
tail -n $TAIL $i >>phperrlog.txtwithor
I would probably start with a blacklist and add additional patterns to it over time when I notice lines I don’t want to see anymore. An initial blacklist could contain
to mach your samples.