error_log ---> how big does it grow?

jols

Well-Known Member
Mar 13, 2004
1,110
3
168
In php.ini we've got log_errors = On and it is a very good feature in that php errors are sent to a error_log file in the same directory as the script, etc.

BUT, I just found an error_log file in a hosted customers account that was over 600,000 lines deep! It had been collecting php errors for more than a year.

Is there a way to have the system rotate these individual account error_log files so they don't get so huge?

Thanks much.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
I believe this may possibly have to do with a recent Cpanel update on server
running Apache 2.2.11 but I am still investigating the issue but I have seen
several hundred servers start generating large error_log files in the locations
where scripts are run shortly after applying recent Cpanel updates.

As for what to do with the error_log files, they are easy to locate and
then sweep or archive how ever you would like. This basic example
just simply deletes the files but you could expand to do what you wish:

Code:
#!/bin/bash
IFS=""$"

cd /home

ls /var/cpanel/users | while read CPLN; do
    find ./${CPLN}/public_html -type f -name 'error_log' | xargs rm -f
done
A little more sophisticated approach, archiving the files:
Code:
#!/bin/bash
IFS="$"

TLOG="/tmp/tmp_error_search.$$"

if [ -e ${TLOG} ]; then
   rm -f ${TLOG}
   /bin/touch ${TLOG}
   /bin/chmod 600 ${TLOG}
fi

cd /home   #Nice starting point

ls /var/cpanel/users | while read CPLN; do
    echo "$(date) I will now search ${CPLN}'s account for PHP error_log files ..."
    find /home/${CPLN}/public_html -type f -name 'error_log' > ${TLOG}
done

if [ -e ${TLOG} ]; then
  echo "$(date) I have built my list of error_log files and am now archiving those files ..."
  cat ${TLOG} | while read MLINE; do
     if [ -e ${MLINE}.bz2 ]; then
        rm -f ${MLINE}.bz2 
        echo "$(date) Removed old archive ${MLINE}.bz2 from hard drive ..."
     fi
     echo "$(date) Compressing ${MLINE} into new bzip2 archive ..."
     bzip2 -9 "${MLINE}"
  done
  rm -f ${TLOG}
fi
echo "$(date) Finished processing user error_log files ..."
# End of Script
 
Last edited:

jols

Well-Known Member
Mar 13, 2004
1,110
3
168
Hey thanks for this!

I have a couple of dumb follow up questions if you don't mind:

1 -- So I take it that you could swap ".bz2" with ".zip" or ".tar" if you wanted to use other compression formats?

2 -- Would adding a file check size go something like the following?, e.g. test the size of the error_log file and do nothing unless it is over 50MB:

--------------------- Modified area follows:
FileSize=$(du -ks ${TLOG} | awk '{print $1}')
if [ $FileSize -gt 5000000 ]
then
cat ${TLOG} | while read MLINE; do
if [ -e ${MLINE}.bz2 ]; then
rm -f ${MLINE}.bz2
echo "$(date) Removed old archive ${MLINE}.bz2 from hard drive ..."
fi
echo "$(date) Compressing ${MLINE} into new bzip2 archive ..."
bzip2 -9 "${MLINE}"
fi
done
---------------------