4

I would like to delete some messages from an existing postfix queue based on a string match in the message body. Any suggestions?

11

This is fairly simple:

find /var/spool/postfix/deferred/ -type f \
        -exec grep -l 'body string here' '{}' \; | \
    xargs -n1 basename | xargs -n1 postsuper -d

Adjust path (if non-default), and the -n1 in the second xargs isn't strictly needed, but gives a better sense that it's actually doing something.

3
  • He didn't specify which queue.
    – adaptr
    Apr 25 '12 at 8:17
  • 3
    True. For a different queue, use that instead of deferred in the find portion. postsuper works on a number of queues -- hold, incoming, active and deferred -- or you can specify it at the end ( ... | xargs -n1 -i postsuper -d '{}' bounce )
    – techieb0y
    Apr 27 '12 at 1:09
  • And to dry-run this (count how many mails would be deleted without actually doing that), you can run the command while replacing the last part xargs -n1 postsuper -d with wc -l.
    – tanius
    Dec 1 '18 at 2:36
1

Perhaps you should end that with > delfile.txt then you can review what you deleted and then delete the text file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.