Skip to content

Instantly share code, notes, and snippets.

@shollingsworth
Last active September 11, 2023 16:49
Show Gist options
  • Save shollingsworth/3c9399fee286d7cad988f38483bb2d8a to your computer and use it in GitHub Desktop.
Save shollingsworth/3c9399fee286d7cad988f38483bb2d8a to your computer and use it in GitHub Desktop.
iterate through postfix queue and selectively delete entries
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
mapfile -t ids < <(mailq | grep -E '^[0-9A-F]' | awk '{print $1}')
for id in "${ids[@]}"; do
postcat -q "${id}" | less
echo "Remove? (y)"
read -r RM
RM=$(echo "${RM}" | tr '[:upper:]' '[:lower:]')
if [[ "${RM}" = "y" ]]; then
echo "Deleting ${id}"
postsuper -d "${id}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment