I run this script every 15 minutes to record the IP of four dynamic hosts I have setup at duckdns.org.
DUCKDNS=( "sub1.duckdns.org"
"sub2.duckdns.org"
"sub3.duckdns.org"
"sub4.duckdns.org" )
function resolveIP () {
CURRENT_IP=$(dig +short $1)
echo $CURRENT_IP
}
for HOST in "${DUCKDNS[@]}"
do
IP=$(resolveIP $HOST)
echo -e "$HOST ... $IP"
done
When I run the script from the shell, I receive an IP value every time. When I run the script via cron, the script returns null values sporadically.
I believe the issue is related to a 2(SERVFAIL) error I noticed when running host (not dig). This is the response from host:
host sub1.duckdns.org
sub1.duckdns.org has address 66.66.66.66 (NOTE: This value is correct)
Host sub1.duckdns.org not found: 2(SERVFAIL)
sub1.duckdns.org mail is handled by 50 sub1.duckdns.org.
Though an error is returned, the IP address is correct and the script returns it. What is troubling is sometimes is it's not consistent. The script extracts the value when run from the shell every time and most of the time when run via cron.
After setting up my subdomains with DuckDNS.org, I've read that it may not have been a wise choice. Perhaps it's just an issue with the DuckDNS service? If so, any recommendations for other dynamic DNS providers?
I feel like I'm living a bash version of the double slit experiment. Any thoughts on what could be causing this null IP behavior?