A cron script for php and apache errors

I run 3 sites and have been bugged a lot by php errors and apache errors . So I wanted to figure out an automated and scheduled way to do this . I sat down and wrote a bash script which I now run on cron and relax . It is not perfect , but saves the headache and heartache . In this post I wanted to share this script with you hoping that it might be useful . Here is the script

#/bin/bash

# myperrlog v1.0
# by Shakthidharan http://shakthisoft.net
#
# parse error logs on your server and send you daily updates to email

# configure options
EMAIL=enter email here

WORKDIR="/root"
TAIL=5  # number of entries to send
IGNORE="/backup" # path to ignore

# script starts 'ere

cd $WORKDIR
rm phperrlog.txt

LIST=`locate error_log  | grep -v $IGNORE`;
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 "server error logs - $today" $EMAIL  < phperrlog.txt
fi

Usage

Set the email and other configration options first.

Then, add the script to your cron using, crontab -e. This will start the script every day at the time you want .

Technorati : , , ,
Del.icio.us : , , ,

Bookmark and Share
This entry was posted in Blogging, General and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 4 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>