OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Re: cleaning the queue, also: performance with many undeliverables

From: Paul C (pczarkowgil.com.au)
Date: Mon May 12 2003 - 18:00:30 CDT


> At 04:08 PM 5/12/03 -0400, Ben Rosengart wrote:
> >I have several thousand undeliverable bounces in my queues. I'd
> >like to tell Postfix to route all mail for the domain in question
> >to /dev/null. Is this doable, or has the transport already been
>
> If they are all for the same destination domain "example.com" you can
> delete them with something like:
>
> mailq | perl -e 'print scalar(<>); $/=""; while (<>) {s/\n//g; s/\s+/ /g;
> print $_,
> "\n"}' | grep example.com | awk '{print $1}' | postsuper -d -
>
> Untested, but should work. There are surely 100 other ways to do this,
> probably most of them better than my example. To delete all bounces you
> can grep on "DAEMON" or whatever mailq shows as the sender.
>
> If someone can show an example based on the age of the bounce, that would
> be really great as my perl foo is non-existent and limited to ripping off
> other's code. Thanks to Colin Campbell for the perl snippit above.

I use the following to clean my spool in emergency situations where i HAVE
to get the spool size down (or when i receive a kazillan spams all with
yahoo as the forged from address). the commented out lines can be used to
troll thru a two layer structure of the spool dir. obviously replace
"PATTERN" with the pattern you want to delete with.

#!/usr/bin/perl

$| = 1;
$spool = "/var/spool/postfix";
dirstocheck = ("active","deferred"); # can be advisable to include
"incoming" in this array.

foreach ( dirstocheck ) {
        $level1 = "$spool/$_";
        print "CWD = $level1\n";
        opendir(ROOTDIR,"$level1");
        DIR1 = readdir(ROOTDIR);
        shift DIR1; shift DIR1;
        foreach (DIR1) {
        $dir1 = $_;
        #print "$_\t";
        opendir(DIR1,"$level1/$dir1");
        DIR2 = readdir(DIR1);
        shift DIR2; shift DIR2;
        #foreach (DIR2) {
        # $dir2 = $_;
# #print "$_\t";
# opendir(DIR2,"$level1/$dir1/$dir2");
# print "$level1/$dir1/$dir2\n";
# DIR3 = readdir(DIR2);
# shift DIR3; shift DIR3;
                foreach (DIR2) {
                        $dir3 = $_;
                        #print "$_\t";
                        #print "$dir1/$dir3\t";
                        open(CMD, "/usr/sbin/postcat $level1/$dir1/$dir3 |
grep PATTERN |");
                        print ".";
                        while (<CMD>) {
                                if (/PATTERN/) {
                                        system "postsuper -d $dir3";
                                        $Match++;
                                        print "*";
                                        last;
                                }
                        }
                        $Count++;
                }
        #}
        }
        print "\n\n";
}
print "\nTotal Files : $Count\nMatched Files: $Match\n";