| Delete a Group of Messages from the Postfix Queue |
|
This article will show you how to delete a group of messages out of a postfix mail queue, from the command line, using a number of standard Linux commands. It is not intended to be a tutorial on Postfix, GAWK, grep, regular expressions, or any other Linux command, but many of them will be covered in a little bit of detail and, at the end, you will be able to add this to your bag of tricks.
gawk 'BEGIN {RS = ""} /member[0-9]@domain.com/ {print $1}' | \ tr -d '*!' | sudo postsuper -d - There is a similar command in the postsuper manual, but it didn't want to work right for me, so I tweaked it and got this. The back slashes in the command allow you to span the command over multiple lines on the Linux system. Now, let's break this massive command down: mailqWe all know what mailq does. It prints out the queue. Enough said. tail -n +2
Tail is a standard command that will print the last 10 lines (or the specified number of lines) of a file. The So now we are piping the output of mailq, minus the first line, to grep. The -v option tells grep to invert the match, so it will only display the non-matching lines. The regular expression tells it to find all lines with zero or more spaces at the beginning of the line followed by an open parenthesis. The lines of the mail queue listing that will match that regular expression are status lines and do not contain any information that is needed in further processing. gawk 'BEGIN { RS = "" } /member[0-9]@domain.com/ { print $1 }'At this point we have the mail queue without the header line and without any status lines. We need to extract just the message ID numbers out of the queue for the messages that match the ones we want to delete. For this we will use gawk, the GNU version of the awk scripting language. gawk is great for processing text files with records separated by some delemiter.
Once we invoke gawk we give it the command
The next part of the gawk command is
tr is a command that translates or deletes characters. The
Now for the action part. postsuper is the Postfix superintendent command. The Conclusion
There we have it. The queue is all cleaned up. Just for reference, here are a few other fields from the mail queue that can be referenced from gawk:
You must be logged in to leave a comment.
No Account? Join Now! (It's Free.) Powered by !JoomlaComment 3.25
3.25 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
||||||||||||