Last active
November 23, 2016 13:26
-
-
Save Ham5ter/fe34f0f63aefa7328cfb20d95847e35d to your computer and use it in GitHub Desktop.
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 | |
# | |
# Very simple Script that checks a configured DNS Record, | |
# If it changed since the Last time this script was run, | |
# it alerts a specified Mail Recipient | |
# http://tecadmin.net/ways-to-send-email-from-linux-command-line/ | |
# | |
# Config Stuff | |
DOMAIN="example.com" | |
DNS_SERVER="8.8.8.8" | |
MAIL_RECIPIENT="[email protected]" | |
MAIL_SUBJECT="Mail Alert DynDNS" | |
# Dont touch stuf after this comment, if you dont know what you are doing! | |
OLDIP_FILE="OLDIP.txt" | |
CURRENTIP=$(dig +noall +answer +nocomments ${DOMAIN} @${DNS_SERVER} | awk '{print $5}') | |
OLDIP=$(cat "${OLDIP_FILE}") | |
echo "${CURRENTIP}" > "${OLDIP_FILE}" | |
if [ "${OLDIP}" == "${CURRENTIP}" ]; then | |
exit 0 | |
else | |
echo "ERROR=DNS RECORD CHANGED!" | |
echo "DOMAIN=\"${DOMAIN}\"" | |
echo "DNS_SERVER=\"${DNS_SERVER}\"" | |
echo "OLD_IP=\"${OLDIP}\"" | |
echo "NEW_IP=\"${CURRENTIP}\"" | |
# Send Mail | |
echo "DNS RECORD for \"${DOMAIN}\" changed from \"${OLDIP}\" to \"${CURRENTIP}\"" | mail -s ${MAIL_SUBJECT} ${MAIL_RECIPIENT} | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment