Skip to content

Instantly share code, notes, and snippets.

@ypresto
Last active December 23, 2015 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypresto/6559955 to your computer and use it in GitHub Desktop.
Save ypresto/6559955 to your computer and use it in GitHub Desktop.
# Place this file on /etc/update-ddns.conf
# SECURITY: run `chmod 600 /etc/update-ddns.conf'
# to make it unreadable by non-root users.
DOMAIN=
PASSWORD=
HOST=
#!/bin/bash
CONFIG_FILE='/etc/update-ddns.conf'
IP_CACHE_FILE='/tmp/update_ddns_ip'
# sources DOMAIN= , PASSWORD= and HOST=
source $CONFIG_FILE
old_ip=`[ -e $IP_CACHE_FILE ] && cat $IP_CACHE_FILE || echo ''`
new_ip=`wget --quiet -O - 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?ip'`
if [ "$old_ip" = "$new_ip" ]; then
echo "NO CHANGE ($new_ip)"
exit 0
fi
url="http://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$DOMAIN&p=$PASSWORD&h=$HOST"
result=0
wget --quiet -O - "$url" 2>/dev/null | grep 'status=0' >/dev/null && result=1
if (( !$result )); then
echo 'FAILED'
exit 1
fi
echo $new_ip > $IP_CACHE_FILE
echo "UPDATED ($new_ip)"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment