Created
September 25, 2015 16:24
-
-
Save rushipkar90/5d705501b26339e73e70 to your computer and use it in GitHub Desktop.
add_mailchannels_spf.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LIST=$1 | |
LOG=spf_add.log | |
date > $LOG | |
lecho() { | |
echo $@ 2>&1 | tee -a $LOG | |
} | |
backup_zones(){ | |
FILE=$(hostname)-$(date +%s)-zones.tgz | |
tar czf $FILE /var/named/*.db | |
} | |
add_to_server(){ | |
for ZONEFILE in $(ls /var/named/*.db) | |
do | |
if [ -z "$(grep mailchannels $ZONEFILE)" ]; then | |
DOM=$(echo $ZONEFILE | awk -F/ '{print $NF}' | sed 's/\(.*\)\.db/\1/') | |
if [ -n "$DOM" ]; then | |
OLD_SERIAL=$(cat $ZONEFILE | grep -i serial | awk '{print $1}') | |
NEW_SERIAL=$((OLD_SERIAL+1)) | |
lecho $ZONEFILE" changing serial from "$OLD_SERIAL" to "$NEW_SERIAL | |
sed -i "s/$OLD_SERIAL/$NEW_SERIAL/" $ZONEFILE || lecho "s/$OLD_SERIAL/$NEW_SERIAL/ ---> FAILED" | |
lecho "Adding SPF record" | |
echo $DOM'. 14400 TXT "v=spf1 a mx include:relay.mailchannels.net ?all"'>>$ZONEFILE | |
fi | |
else | |
lecho $ZONEFILE" already set" | |
fi | |
done | |
} | |
backup_zones | |
if [ -f $FILE ]; then | |
add_to_server | |
/scripts/dnscluster syncall | |
else | |
lecho "Couldn't backup, aborting" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment