Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remote processing of multiple mail server's OpenDMARC history files
#!/bin/bash
# Script for remote processing of multiple mail server's OpenDMARC history files
# Based on a script from Hamzah Khan (http://blog.hamzahkhan.com/)
set -e
cd /tmp
# Remote Hosts, Database, and History File Info
HOSTS='mx1.example.com mx2.example.com mx3.example.com'
DBHOST='mysql.example.com'
DBUSER='opendmarc'
DBPASS='secretpassword'
DBNAME='opendmarc'
HISTDIR='/var/spool/opendmarc'
HISTFILE='opendmarc.dat'
for HOST in $HOSTS; do
#Create a remote copy of history file, copy and rename the contents to a local file, then remove the remote copy
ssh -i /tmp root@${HOST} "touch ${HISTDIR}/${HISTFILE}; mv ${HISTDIR}/${HISTFILE} ${HISTDIR}/${HOST}.$$; cat ${HISTDIR}/${HOST}.$$; rm ${HISTDIR}/${HOST}.$$"
# Merge the local history files so opendmarc-import only needs to run once
cat ${HOST}.$$ >> opendmarc-merged.$$
done
# Import data and send reports
/usr/sbin/opendmarc-import –dbhost=${DBHOST} –dbuser=${DBUSER} –dbpasswd=${DBPASS} –dbname=${DBNAME} –verbose < opendmarc-merged.dat
/usr/sbin/opendmarc-reports –dbhost=${DBHOST} –dbuser=${DBUSER} –dbpasswd=${DBPASS} –dbname=${DBNAME} –verbose –interval=86400 –report-email "postmaster@example.com" –report-org "Example.com"
/usr/sbin/opendmarc-expire –dbhost=${DBHOST} –dbuser=${DBUSER} –dbpasswd=${DBPASS} –dbname=${DBNAME} –verbose
# Delete the local .dat files after processing
rm -rf *.$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.