Finddelete
From Ezee.co.uk
This is a seriously nasty flung together script. A client had an application that was exploited by spammers. He realised pretty quickly and shut down his mailserver.
He needed to delete the spammers trash from his queue quickly so he could get his mail system back up and running. I put this script together just to do this.
It has to be the nastiest bit of code I have ever written and doesn't even take command line options. I will re-rewrite this when I get a few minutes as it was very useful.
#!/usr/bin/php -q
<?php
# Deletes a file if it contains "searchstring"
$path=$argv[1];
$string=$argv[2];
$deletecount=0;
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (is_file("$path/$file")) {
$contents=file_get_contents("$path/$file");
if (eregi("$string",$contents)) {
exec ("rm -f $path/$file");
#Delete the queue file as well;
if ($file[0]=='q') {
$file[0]='d';
} elseif ($file[0]=='d') $file[0]='q';
exec ("rm -f $path/$file");
echo "Deleting $file\n";
$deletecount++;
}
}
}
closedir($handle);
}
echo "Deleted $deletecount file(s)\n";
?>
