Routing the world

Routing & IT System Administration

Archive for April 2013

Delete messages from Postfix Queue based on from or to addresses

leave a comment »

When you need to delete messages from a Postfix Queue based on the From or To headers you can do it using the next “one-liner” commands:

  • For message deletion in a Postfix Queue based on From address

mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "address@mail.example.com" && $9 == "") print $1 } ' | tr -d '*!' | xargs rm

  • For message deletion in a Postfix Queue based on To address

mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "address@mail.example.com" && $9 == "") print $1 } ' | tr -d '*!' | xargs rm

What changes between the two commands is the position the awk command get to make parsing in order to obtains the MSGID before push it to delete command.

You could change "xargs rm" to "wc -l" to get the number of messages affected by the message group based on the From or To address. This must be done ALWAYS BEFORE delete the messages from the queue.

UPDATE 24/04/2013: If you are using a modern version of Postfix with queue in a complex directory structure, you have to change the last argument “xargs rm” to “xargs -rn1 postsuper -d“. This is done because postsuper command can delete messages from queue in all that complex structure and you don’t need to enter each directory to be able to delete the files.

Written by Root

April 24, 2013 at 09:00

Count the number of files per directory in the Filesystem

leave a comment »

When you need to know the number of files in a directory tree you can use the following sentence:

find ~ -type d -exec sh -c "fc=\$(find '{}' -type f | wc -l); echo -e \"\$fc\t{}\"" \; | sort -nr

Written by Root

April 22, 2013 at 10:24

%d bloggers like this: