Este script sirve para buscar en los logs de Postfix 2.9.6 la historia de entrega de los correos que cumplan con el from=
y el to=
que se indiquen en el primer y segundo argumento del script, respectivamente.
#!/bin/bash # Configuration variables REQUIREMENTS="gawk grep" LOGSOURCES="/var/log/mail.info.1 /var/log/mail.info" # Check requirements which $REQUIREMENTS > /dev/null 2>&1 || { echo The following required programs were not found: for R in $REQUIREMENTS; do which "$R" > /dev/null 2>&1 || echo "$R" done exit 63 } # Check arguments [ $# -eq 2 ] || { echo Usage: "$0" source_address destination_address exit 1 } # These work for Postfix 2.9.6 function get_filter_from() { echo 'BEGIN { FS="[ :]+"} /from=<'$1'>/ && !/NOQUEUE/ { print $8 }' } function get_filter_to() { echo 'BEGIN { FS="[ :]+"} /to=<'$1'>/ && !/NOQUEUE/ { print $8 }' } function awniq() { gawk '!a[$0]++' } FILTER_FROM=$(get_filter_from "$1") FILTER_TO=$(get_filter_to "$2") # For each mail ID found in both from= and to= lines... for ID in $(grep -f <(gawk "$FILTER_FROM" $LOGSOURCES | awniq) \ <(gawk "$FILTER_TO" $LOGSOURCES | awniq)) do echo ====== $ID ====== grep -- "$ID" /var/log/{mail.info.1,mail.info} done