1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

error_log How to delete all via SSH?

Discussion in 'Apache' started by Divvy, Dec 6, 2011.

  1. #1
    Hello,

    Today I check few of my websites folder under my web server I found that most of the folders contains the file "error_log" at some folders it is in smaller size but in others its around 600-900 MB in size per file. My question is

    1. Whether its wise to stop creation of that file by Apache? If yes then how to stop it?

    2. Second question is can we stop it for only few websites?

    3. And is that safe to delete error_log file? If yes how to search that file in SSH and how to delete it using one command as it would be really hard to delete one by one from each folder.

    EDIT about question 3:

    I found this command:
    cd /home
    find . -name error_log
    find . -name error_log -exe rm -f {} \;
    find . -name error_log
    
    the above commands will first find all files and list them, the next one will find all files and remove them, the last will confirm that all the error log files have been deleted.
    Code (markup):
    But the command below dont work:
    find . -name error_log -exe rm -f {} \;
    Code (markup):
    Please help me with this. Thank you!

    -Regards.
     
    Divvy, Dec 6, 2011 IP
  2. RHS-Chris

    RHS-Chris Well-Known Member

    Messages:
    1,007
    Likes Received:
    35
    Best Answers:
    10
    Trophy Points:
    150
    #2
    Hi there,

    Pretty sure you are missing the "c" off the end, should look something like so:

    find . -name error_log -exec rm -f {} \;
    Code (markup):
    Alternatively, I would suggest you do not remove the file completely, as is is useful for tracking down errors. I usually just clear them out, by doing something along these lines:

    echo > /home/username/public_html/error_log
    Code (markup):
    Chris
     
    RHS-Chris, Dec 6, 2011 IP
  3. Leno B

    Leno B Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    you can clear the error logs of apache,mysql,exim by using the below steps

    >> First keep last 1000 logs to a file
    tail -1000 /var/log/messages /var/log/messages.bbkp

    >> clear full logs in messages

    > /var/log/messages

    >> tail -1000 /var/log/messages.bkp > /var/log/messages

    done
     
    Leno B, Dec 7, 2011 IP
  4. ideamine

    ideamine Member

    Messages:
    83
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    28
    #4
    Hi Divvy,

    I can see that you have 3 questions.
    1. Whether its wise to stop creation of that file by Apache? If yes then how to stop it?
    The file error_log is one of the most important files of apache and removing/stopping it is not recommended. This file helps us in trouble shooting issues related with apache.

    2. Second question is can we stop it for only few websites?
    We can assign a specific error_log file for each domain name in httpd.conf so that we can easily find the errors related to that domain.

    3. And is that safe to delete error_log file? If yes how to search that file in SSH and how to delete it using one command as it would be really hard to delete one by one from each folder.
    The location of the error_log file depends on which control panel is installed. We can also use the command "locate error_log" to find the location. You can clear the file by giving this command "> error_log".
     
    ideamine, Dec 13, 2011 IP
  5. muthukumar664

    muthukumar664 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    Kindly move the logs to Some other Destination

    For Ex:

    mv access_log access_log.old

    Which will resolve this issue
     
    muthukumar664, Dec 14, 2011 IP
  6. stardust.x7

    stardust.x7 Active Member

    Messages:
    369
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    90
    #6
    You can run :

    This will remove all error_log from public_html dir of every cP users.
     
    stardust.x7, Dec 22, 2011 IP
  7. Pathan

    Pathan Well-Known Member

    Messages:
    2,196
    Likes Received:
    218
    Best Answers:
    0
    Trophy Points:
    165
    #7
    Try the following:

    find /home/ -type f -name error_log -delete
     
    Pathan, Jan 14, 2012 IP
    postcd likes this.
  8. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #8
    I think this one is most lightweight command of all mentioned. I found "rm -rf" takes ages to delete alot of files in directory etc. But find command mentioned by Pathan works really way faster.

    one can also set only delete files if size is larger than 500kb for example:
    find /home -type f -name error_log -size +500k -print

    "-print" shows what files match your criteria
    "-delete" deletes without confirmation
     
    postcd, Jun 2, 2014 IP
  9. Tier_net

    Tier_net Active Member

    Messages:
    35
    Likes Received:
    5
    Best Answers:
    3
    Trophy Points:
    58
    #9
    To clear without removing:

    for file in /home/*/public_html/error_log; do echo > $file; done;

    you can also crawl into deeper directories by adding some "*"'s

    for file in /home/*/public_html/*/error_log; do echo > $file; done;

    for example
     
    Tier_net, Jun 4, 2014 IP
  10. MargoFarrel

    MargoFarrel Member

    Messages:
    154
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    33
    #10
    I like that I even don't need to ask a question) Just come here and find everything you need. Thanks for your valuable answers!
     
    MargoFarrel, Jun 17, 2022 IP