Skip to content

Instantly share code, notes, and snippets.

@mdcollins05
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdcollins05/25f106d9e299459bacee to your computer and use it in GitHub Desktop.
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.
#!/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