Skip to content

Instantly share code, notes, and snippets.

@dotben
Created December 29, 2010 19:47
Show Gist options
  • Save dotben/758966 to your computer and use it in GitHub Desktop.
Save dotben/758966 to your computer and use it in GitHub Desktop.
Shell script to update a subdomain managed by Linode with the IP of a dyndns managed domain
#!/bin/sh
## Shell script to update a subdomain managed by Linode with the IP of a dyndns managed domain
##
## Use this script if you don't want to CNAME the dnydns domain for privacy/security reasons. You
## probably want to run this as a cronjob.
##
## You will find the DOMAIN_ID in the text zone file of your domain between square brackets. The
## RESOURCE_ID is the id arg on the edit url of your chosen subdomain entry.
##
## Based on http://www.cnysupport.com/index.php/linode-dynamic-dns-ddns-update-script
## Ben Metcalfe / dotben / http://benmetcalfe.com/blog/ -- GPL
LINODE_API_KEY=<your linode key>
DOMAIN_ID=<domain id, see above>
RESOURCE_ID=<resource id, see above>
DYN_DNS_DOMAIN=yourdomain.dyndns.com
WAN_IP=`ping -c1 -n -t0 $DYN_DNS_DOMAIN | head -n1 | sed "s/.*(\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)).*/\1/g"`
touch ~/currentip.$DYN_DNS_DOMAIN.txt ## create this file if it doesn't exit
OLD_WAN_IP=`cat ~/currentip.$DYN_DNS_DOMAIN.txt`
if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then
echo "IP Unchanged"
else
echo $WAN_IP > ~/currentip.$DYN_DNS_DOMAIN.txt
wget -qO- https://api.linode.com/?api_key="$LINODE_API_KEY"\&api_action=domain.resource.update\&DomainID="$DOMAIN_ID"\&ResourceID="$RESOURCE_ID"\&Target="$WAN_IP"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment