Thursday, 23 May 2013

Manually update dynds from a cron job when dd-wrt's builtin inadyn client segfaults

OK so dd-wrt's builtin Dyndns.org updater somehow gave in. Tried changing it to opendns, played around with settings etc → no avail.

Now, it's technically possible to just update dyndns every minute. But that will definately break the update policy and I'll be banned. So I made this little script that I put on a machine in the internal network:

cat update-dyndns.sh
#!/bin/sh
# Arno's update-dns-script, run by cron every 1 min


# Get current ROUTER IP
ROUTERIP=`wget -q -O - http://router|grep "IP: "|sed 's/<[^>]*>//g'|sed 's/.*IP..//'`
CMNIP=`ping -c 1 -w 1 <myhostname>|grep PING |sed 's/^.*(//'|sed 's/).*//'`

# echo $ROUTERIP
# echo $CMNIP

if [ "$ROUTERIP" = "$CMNIP" ]; then
 # echo IPs are the same
 # don't do anything :)
 echo "Last DDNS check at " `date` > /root/dnsupdate.txt
else
 # echo IPs differ
 # echo We need to update it
 #update now
 wget -q -O - "https://<user>:<password>@members.dyndns.org/nic/update?hostname=<myhostname>" >/dev/null
 echo "Last DDNS update at" `date` > /root/dnsupdate.txt
fi


And to make sure it's run every minute, "crontab -e" and insert:
*       *       *       *       *       /root/update-dyndns.sh

That was it :) Didn't bother removing the debug/explanatory comments ;)

No comments:

Post a Comment