Forked from kennethkalmer/grep-postfix-message-ids-osx.sh
Last active
August 29, 2015 14:07
-
-
Save chikatambun/c58bc68d1dd2e16b15b4 to your computer and use it in GitHub Desktop.
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/sh | |
# OSX friendly version by jeff donovan | |
# | |
# Grep for a pattern through a Postfix mail log, collect the message ids into a temporary | |
# file and then grep for all occurrences of the ID's in the maillog. | |
# This is a very intensive operation since it requires 1+N greps through the entire log file, | |
# where N is the number of unique ID's returned from the first grep. | |
# | |
# Usage sample: | |
# ./grep-postfix-message-ids.sh @gmail.com | |
# ./grep-posftix-message-ids.sh "from=<kenneth.kalmer" | |
# | |
if [ -z $1 ]; then | |
echo "Usage: `basename $0` pattern [/var/log/mail.log]" | |
echo | |
exit 1 | |
fi | |
PATTERN=$1 | |
if [ -z $2 ]; then | |
MAILLOG=/var/log/mail.log | |
else | |
MAILLOG=$2 | |
fi | |
if [ ! -f $MAILLOG ]; then | |
echo "Maillog $MAILLOG doesn't exist" | |
echo | |
exit 1 | |
fi | |
touch /var/log/tempfile | |
TEMPFILE=/var/log/tempfile | |
egrep "$PATTERN" $MAILLOG | awk '{print $6}' | tr -d : | uniq > $TEMPFILE | |
for message_id in `cat $TEMPFILE` | |
do | |
grep $message_id $MAILLOG | |
done | |
rm -f $TEMPFILE |
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/sh | |
# Grep for a pattern through a Postfix mail log, collect the message ids into a temporary | |
# file and then grep for all occurrences of the ID's in the maillog. | |
# This is a very intensive operation since it requires 1+N greps through the entire log file, | |
# where N is the number of unique ID's returned from the first grep. | |
# | |
# Usage sample: | |
# ./grep-postfix-message-ids.sh @gmail.com | |
# ./grep-posftix-message-ids.sh "from=<kenneth.kalmer" | |
# | |
if [ -z $1 ]; then | |
echo "Usage: `basename $0` pattern [/var/log/maillog]" | |
echo | |
exit 1 | |
fi | |
PATTERN=$1 | |
if [ -z $2 ]; then | |
MAILLOG=/var/log/maillog | |
else | |
MAILLOG=$2 | |
fi | |
if [ ! -f $MAILLOG ]; then | |
echo "Maillog $MAILLOG doesn't exist" | |
echo | |
exit 1 | |
fi | |
TEMPFILE=`tempfile` | |
egrep "$PATTERN" $MAILLOG | gawk '{print $6}' | tr -d : | uniq > $TEMPFILE | |
for message_id in `cat $TEMPFILE` | |
do | |
grep $message_id $MAILLOG | |
done | |
rm -f $TEMPFILE 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment