Zionetrix::Git
Repositories
Help
Report an Issue
postfix_scripts
Code
Commits
Branches
Tags
Search
Tree:
774e0ce
Branches
Tags
master
postfix_scripts
scripts
mailid_to_messageid
Initial commit
Benjamin Renard
commited
774e0ce
at 2016-01-19 19:51:30
mailid_to_messageid
Blame
History
Raw
#!/bin/bash MAILID="$1" [ -z "$MAILID" ] && echo "Usage : $0 [mailid]" && exit 1 DEBUG=0 [ "$2" == "-d" ] && DEBUG=1 MAX_LOG=9 function search_msgid () { MAILID="$1" MAILLOG="$2" [ ! -f "$MAILLOG" ] && MAILLOG="$MAILLOG.gz" [ -f "$MAILLOG" ] && zgrep "$MAILID: message-id=" $MAILLOG|sed 's/^.*message-id=<\([^>]*\)>.*$/\1/' } [ $DEBUG -eq 1 ] && echo "Search message ID from mail ID $MAILID ..." res=$( search_msgid "$MAILID" /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_msgid "$MAILID" /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