
This work is licenced under a Creative Commons Licence.
I occasionally have issues with slow DNS propagation between my DNS servers and myself. Instead of sitting there trying to see what is happening, I have written a little bash script to let me know when it has updated (I know this can be improved, but it works).
#!/bin/bash
###
### Script to check if a DNS entry exists. If it does not it will
### check again in 60 seconds. If it does exist, it will play a file
###
digcommand=$(dig "$1" | grep "ANSWER SECTION")
while true
do
if [ -z "$digcommand" ] ; then
curtime=$(date | cut -d" " -f4)
echo "$curtime - No dns record found"
sleep 60
else curtime=$(date | cut -d" " -f4)
echo "$curtime - Match found"
# echo "dns updated" > dns
# cat dns | mail -s "DNS UPDATED" myemailaddress@mydomain.tld
# rm dns
mpg123 ~/path/to/an.mp3
break
fi
done
The commented lines are useful if your server can use "mail" to send you an email. Obviously you'll want to change the email if you do that, and you'll want to change the path to the mp3 also.
EDIT: It has been brought to my attention that this script is A Bad Thing. Why? Because even failed DNS lookups are usually cached, so it will never return a match, as it will just see that the cached record that is unmatched.