Postfix mailq search

I couldn’t find a script to search the Postfix mail queue so I wrote one. It’s a bash script and can be downloaded here (or just copy and paste it to file of your choice). I call it ssubject.sh. It ends up just spitting out the queue id’s of messages that match. Usage: “ssubject.sh “some words to look for”

  1. #!/bin/bash
  2.  
  3. SUBJECT=$1
  4.  
  5. /usr/sbin/postqueue -p | awk {'print $1'} | grep -v (host | \
  6.         grep -v @ | grep -v (delivery | grep -v (Host | grep -v (connect | \
  7.         grep -v (lost | grep -v (conversation | grep -v -Queue | \
  8.         sed 's/*//g' | sed '/^$/d' > /tmp/queue_ids.txt
  9.  
  10. cat /tmp/queue_ids.txt | while read line; do
  11.         sudo /usr/sbin/postcat -q ${line}|> | grep "$SUBJECT" > /dev/null 2>&1
  12.         if [ "$?" -eq "0" ]; then
  13.                 echo ${line}|> ;
  14.         fi
  15. done
Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • StumbleUpon
  • del.icio.us
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]