Send PHP Error Logs

PHP Log reporting

Check through your web sites for those pesky PHP error logs

  • You need to have PHP writing errors to the file name ‘error.log'
  • Save the snippet in your /root/bin as ‘sendlog'
  • chmod 700 the file to make it executable
  • As shown add it to crontab (example is hourly)
  • Based on WHM/CPanel directory structure for web pages



#!/bin/bash
# Put the line below (without the #) into your cron "crontab -e" this one is hourly
#0 * * * * /root/bin/sendlog > /dev/null 2>&1

DIR="/home"
LOG="/tmp/sendlog.mail"
rm $LOG &> /dev/null
# Do not check these direcorties
IGNORE=".cpan .cpanm .cpcpan cPanelInstall clamav cpeasyapache virtfs"
# Get list of all directories
LIST='ls /home'
for path in $LIST; do
        # set skip variable
        skip=0
        if [ "$IGNORE" != "" ]; then
                for i in $IGNORE; do
                        [ "$path" == "$i" ] && skip=1 || :
                done
        fi
        if [ "$skip" == "0" ]; then
           #echo "--------------------------------------------------------" >> $LOG
           #echo "Scanning :: $path" >> $LOG
           #echo "--------------------------------------------------------" >> $LOG
           ERRORS='find /home/$path -name error_log'
           for err in $ERRORS; do
                echo "--------------------------------------------------------" >> $LOG
                echo "Error File :: $err" >> $LOG
                echo "--------------------------------------------------------" >> $LOG
                cat $err >> $LOG
                rm $err &> /dev/null
           done
        fi
done
if [ -f $LOG ]
then
    mail -s "PHP Error Log" myname@example.com < $LOG
fi

rm $LOG &> /dev/null