Saturday 21 May 2011

Postfix Queue Management

Again some very useful one liners but this time to manage the Postfix mail queue.

Release messages from hold
mailq | awk '{if($1 ~ /[A-F0-9]+!$/) {gsub(/!/, "", $1); print($1); system(sprintf("postsuper -H%s", $1)); } }'
postqueue -f 
Requeue hold messages to force delivery
mailq | awk '{if($1 ~ /[A-F0-9]+!$/) {gsub(/!/, "", $1); print($1); system(sprintf("postsuper -H%s", $1)); } }' 
Flush the queue
postqueue -f
Clean all MAILER-DAEMON error messages 
Normal Messages
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | postsuper -d -
for me mailq returns the message id with a trailing ! so I use:
mailq | awk '{ if ($7 == "MAILER-DAEMON") print substr ($1, 1, length($1)-1) } ' | postsuper -d -

Messages with errors
mailq | grep MAILER-DAEMON |  sed -e 's/!$//' | cut -d " " -f 1 | postsuper -d -
or
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | sed -e 's/!$//' | postsuper -d -
If you want to delete messages with the ! sign on the end, use
mailq | tail +2 | awk '{ if ($7 == "MAILER-DAEMON") print $1 } ' | cut -d! -f 1 | postsuper -d -
NOTE: Sometimes, you may need to omit the:
tail +2

Possibly Related Posts

No comments:

Post a Comment