Skip to content

Instantly share code, notes, and snippets.

@ypresto

ypresto/update-ddns.conf

Last active Dec 23, 2015
Embed
What would you like to do?
# 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