#!/bin/bash set -euo pipefail if [[ "$1" == "" ]] then echo "Indicate a string to search in the postqueue." exit 54 fi postqueue -p | grep -v '^-' | sed ':a;N;$!ba;s/\n\n/ENTER/g' | sed ':a;N;$!ba;s/\n/ /g' | sed 's/ENTER/\n/g' | grep "$1" |awk '{print($1)}' | while read -r KMSGID do echo "Removing message with ID '${KMSGID}'..." postsuper -d "$KMSGID" done