A few months ago, a client with a Postfix mail server running on RedHat (or Debian, I do not remember) began to have problems with the mail queue (tail-mail). Apparently a user's PC was infected with some Spambot, which was sending a huge amount of spam via the mail server of the company.

Vaccinate the infected PC was only the beginning, because in the tail of the Postfix MTA were still the +20000 mails that had sent the spam bot, to do to erase all of those e-mails?

On the one hand the server was working at full capacity to process the mail queue, this includes spam and legitimate emails from other users.
So to be able to work quietly down the demon of postfix on Redhat (CentOS, Fedora, SuSE) running the following command:

  postfix.redhat: ~ # postfix stop service 

If you use Debian (Knoppix, Ubuntu, etc) can download the service postfix well;

  postfix.deathbian: ~ # / etc / init.d / postfix stop 

Already with the mail server off, we created the file / root / postfix_queue.sh with the following contents:

  mailq | tail +2 | grep-v '^ * (' | awk 'BEGIN (RS = "") 
  # 7 = $ sender, $ 8 = recipient1, $ 9 = recipient2 
  (If ($ 8 == "user@guatewireless.org" & & $ 9 == "") 
        print $ 1) 
  '| Tr-d' *! "  | Postsuper-d -- 

Then we execute permission:

  postfix.deathbian: ~ # chmod 755 / root / postfix_queue.sh 
file: / root / postfix_queue.sh

  mailq | tail +2 | awk 'BEGIN (RS = "") 
  # 7 = $ sender, $ 8 = recipient1, $ 9 = recipient2 
  (If ($ 7 == "usuario.spam guatewireless.org @" & & $ 9 == "") 
  print $ 1) 
  '| Tr-d' *! "  | Postsuper-d -- 

And of course we run our script,

  postfix.redhat: ~ # / root / postfix_queue.sh 

And seeing as automagically disappear thousands of correso of the tail.

So when they suffer another attack of spam, with the help of the script above and can eliminate the tail of the Postfix mail easily. By the way, if someone uses this script, that makes me a favor and go out of it, because I do not use postfix, good and not let my filters or viruses or spam.

Popularity: 18% [?]