Last active
August 29, 2015 14:16
-
-
Save mdcollins05/25f106d9e299459bacee to your computer and use it in GitHub Desktop.
For use in a cron job. It will echo the new IPs to stdout if there are changes.
This file contains 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 | |
## This script is designed to be run via a cron job with the MAILTO variable set to generate an email when output occurs (an IP is added/removed/changed) | |
if [ -f "mailservers_result.txt" ]; then | |
mv mailservers_result.txt mailservers_result.txt.old | |
fi | |
dig +short mx acme.pagerduty.com | sed 's/.$//g' | sed 's/^[0-9][0-9]* //g' | xargs dig +short | sort > mailservers_result.txt | |
if [ -f "mailservers_result.txt.old" ]; then | |
DIFF=$(diff -q 'mailservers_result.txt.old' 'mailservers_result.txt' > /dev/null) | |
if [ $? -ne 0 ]; then | |
echo "Changes detected! New IPs are:" | |
cat mailservers_result.txt | |
fi | |
rm mailservers_result.txt.old | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment