Created
February 6, 2020 02:59
-
-
Save anil3a/43710348a0280e4fec88b00e0455e9c5 to your computer and use it in GitHub Desktop.
Delete email queue from linux mailq - Postfix - ubuntu - Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage | |
# ./delete-mail-containing-email.sh anil@github.com | |
EMAILADDY=$1 | |
if [ -z "$EMAILADDY" ] | |
then | |
echo "Usage: $0 <email adres>" | |
exit | |
fi | |
echo "Delete all emails addressed to $EMAILADDY from our Postfix queue." | |
mailq | tail -n +2 | grep -v '^ *(' | awk -v "address=$EMAILADDY" 'BEGIN { RS = "" } | |
{ | |
# example conditions: | |
# if ( $7 == "MAILER-DAEMON && $8 == address && $9 == "" ) | |
# if ( $7 == "MAILER-DAEMON && $8 == "" && $9 == address ) | |
# if ( $7 == "MAILER-DAEMON && $8 == address || $9 == address ) | |
if ( $7 == address || $8 == address || $9 == address ) | |
print $1 | |
} | |
' | tr -d '*!' | postsuper -d - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage | |
# ./delete-mail-containing-mail-daemon.sh anil@github.com | |
EMAILADDY=$1 | |
if [ -z "$EMAILADDY" ] | |
then | |
echo "Usage: $0 <email adres>" | |
exit | |
fi | |
echo "Delete all emails addressed to $EMAILADDY, and sent by MAILER-DAEMON, from our Postfix queue." | |
mailq | tail -n +2 | grep -v '^ *(' | awk -v "address=$EMAILADDY" 'BEGIN { RS = "" } | |
{ | |
# example conditions: | |
# if ( $7 == "MAILER-DAEMON && $8 == address && $9 == "" ) | |
# if ( $7 == "MAILER-DAEMON && $8 == "" && $9 == address ) | |
# if ( $7 == "MAILER-DAEMON && $8 == address || $9 == address ) | |
if ( $7 == "MAILER-DAEMON" && $8 == address ) | |
print $1 | |
} | |
' | tr -d '*!' | postsuper -d - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment