Jump to content

Recommended Posts

Posted

Since they count towards disk space, any way to disable their generation?

I can log onto my cpanel every half a day and delete them but they tend to hide in random folders on my wordpress installation.

Posted

Error log files aren't that large, but can be a nuisance. Below is a script that will delete all error_log files from your account.

 

Copy the code below into a PHP file:

<?php
error_reporting(0);

## read through directories ##
$it = new RecursiveDirectoryIterator("$_SERVER[DOCUMENT_ROOT]");
foreach(new RecursiveIteratorIterator($it) as $file) {

## remove document root so it doesn't get searched ##
$file = preg_replace("@$_SERVER[DOCUMENT_ROOT]@", "", $file);

## get directory name and file extension ##
$extract = pathinfo($file);
$dname = ($extract['dirname']);
$ext = ($extract['basename']);

## find files ##
if ( preg_match("/error\_log/", $ext, $match) )
   { $files[] = "$dname/$ext"; }
}

## loop through files ##
asort($files);
$files = preg_replace("@//@", "/", $files);
foreach($files as $value)
{
$path = "$_SERVER[DOCUMENT_ROOT]$value";
unlink("$path");
echo "Removed: $path<br>";
}
?>

 

Adapted from Byron's core dump sweeper (http://bybyron.net/helio/cordump_sweeper.txt)

  • Like 1
Posted

You could also add that file to a php include on one of your pages so that when somebody visited your page, it would run the script. If you want to do that you'll need to edit the file so that there's no output like this:

 

{
$path = "$_SERVER[DOCUMENT_ROOT]$value";
unlink("$path");
# echo "Removed: $path<br>";
} 
exit; 
?>

 

Then add this at the bottom of your page:

 

<?php
include("sweeper.php");
?>

  • Like 1
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...