Zionetrix::Git
Repositories
Help
Report an Issue
postfix_scripts
Code
Commits
Branches
Tags
Search
Tree:
774e0ce
Branches
Tags
master
postfix_scripts
scripts
messageid_to_original_mailid
Initial commit
Benjamin Renard
commited
774e0ce
at 2016-01-19 19:51:30
messageid_to_original_mailid
Blame
History
Raw
#!/bin/bash MSGID=$1 [ -z "$MSGID" ] && echo "Usage : $0 [message-id]" && exit 1 DEBUG=0 [ "$2" == "-d" ] && DEBUG=1 MAX_LOG=9 function search_mailid () { MSGID=$1 MAILLOG="$2" [ ! -f "$MAILLOG" ] && MAILLOG="$MAILLOG.gz" [ -f "$MAILLOG" ] && zgrep $MSGID $MAILLOG|head -n 1|sed 's/^.*\: \([^\:]*\): message-id.*$/\1/' } [ $DEBUG -eq 1 ] && echo "Search mail ID from message ID $MSGID ..." res=$( search_mailid "$MSGID" /var/log/mail.log ) if [ -n "$res" ] then echo "$res" exit 0 else [ $DEBUG -eq 1 ] && echo "Not found from log file /var/log/mail.log. Try with archive (Max : $MAX_LOG)" for i in $( seq 1 $MAX_LOG ) do res=$( search_mailid "$MSGID" /var/log/mail.log.$i ) if [ -n "$res" ] then [ $DEBUG -eq 1 ] && echo "Found from log file /var/log/mail.log.$i" echo "$res" exit 0 else [ $DEBUG -eq 1 ] && echo "Not found from log file /var/log/mail.log.$i" fi done [ $DEBUG -eq 1 ] && echo "Not found in archive (Max : $MAX_LOG)" fi exit 1