Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    859

    Default error_log ---> how big does it grow?

    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.

  2. #2
    Member
    Join Date
    Aug 2007
    Posts
    6

    Default

    You can use logrotate for compressing the system files. But I don't think it will compress the logs under a user account. Hope this helps you: LogRotate < AllDocumentation/WHMDocs < TWiki

  3. #3
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    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 by Spiral; 07-11-2009 at 04:32 PM.

  4. #4
    Member
    Join Date
    Mar 2004
    Posts
    859

    Default

    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
    ---------------------

Similar Threads & Tags
Similar threads

  1. how to disable the error_log
    By konrath in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 07-30-2009, 02:14 PM
  2. error_log in each folder
    By thewebhosting in forum cPanel and WHM Discussions
    Replies: 11
    Last Post: 03-21-2009, 05:43 PM
  3. domain error_log
    By mv_ in forum New User Questions
    Replies: 5
    Last Post: 09-27-2008, 02:09 PM
  4. Error_log
    By Skm74 in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-17-2003, 08:51 AM
  5. Error_log
    By Speed in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 02-19-2003, 10:33 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube