Forum Astuces.divers petit script pour rechercher un historique de transaction email

Posté par  . Licence CC By‑SA.
8
25
sept.
2014

principalement en utilisant le log postfix au format par defaut au jour de publication de ce script

#!/bin/sh
#
# small script that search mail address within from or to
# and show the whole transaction log by email ID

case $# in
        3)
        count=0
        sens=$1
        motif=$2
        file=$3
        case $sens in
                from)
                        search='from=<'$motif
                ;;
                to)
                        search='to=<'$motif
                ;;
        esac
        for i in $(grep $search $file | grep -v spam | awk '{print $6}')
        do
                grep $i $file
                echo "----------------------------------------------"
                count=$((count+1))
        done
        echo $count "emails trouvés"
        ;;
        *)
                echo "usage : $0 <from|to> <motif> <fichier>"
                echo ""
        ;;
esac

exemple de sortie :

monscript.sh to userB /var/log/mail.info

Sep 25 18:48:32 ns353998 postfix/pickup[23446]: 6C54D300C04A: uid=1113 from=userA@exampleA.com
Sep 25 18:48:32 ns353998 postfix/cleanup[23627]: 6C54D300C04A: message-id=2CF4662A-2BB3-440A-968B-C212FEDFD507@exampleA.com
Sep 25 18:48:32 ns353998 postfix/qmgr[6330]: 6C54D300C04A: from=userA@exampleA.com, size=2328, nrcpt=1 (queue active)
Sep 25 18:48:32 ns353998 postfix/local[23634]: 6C54D300C04A: to=userB@exampleB.net, relay=local, delay=0.03, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
Sep 25 18:48:32 ns353998 postfix/qmgr[6330]: 6C54D300C04A: removed
----------------------------------------------
Sep 25 19:44:18 ns353998 postfix/cleanup[27816]: 82204300C049: message-id=20140925174411.7E1F4300C04A@exampleB.net
Sep 25 19:44:18 ns353998 postfix/qmgr[6330]: 82204300C049: from=userC@exampleC.com, size=104813, nrcpt=1 (queue active)
Sep 25 19:44:18 ns353998 postfix/local[27825]: 82204300C049: to=userB@exampleB.net, orig_to=userD@exampleD.net, relay=local, delay=7.2, delays=7.2/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION")
Sep 25 19:44:18 ns353998 postfix/qmgr[6330]: 82204300C049: removed
----------------------------------------------
2 emails trouvés

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.