Created
May 11, 2009 14:39
-
-
Save myles/110002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Script to update Linode's DNS Manager for a given name. | |
# | |
# Things you need to change. | |
APIKEY=$(cat ~/.linode-apikey) | |
LASTIP="/tmp/lastip" | |
DOMAIN="domain.com" | |
SOAEMAIL="[email protected]" | |
STATUS="1" | |
RRTYPE="A" | |
RRNAME="home" | |
IFACE="eth0" | |
# Shouldn't need to change anything below here. | |
WGET="wget -qO - https://api.linode.com/api/" | |
NEWIP=$(wget http://checkip.dyndns.com -O - -o /dev/null | sed -r 's/<html><head><title>Current IP Check<\/title><\/head><body>Current IP Address: //g' | sed -r 's/<\/body><\/html>//g') | |
test -e $LASTIP && OLDIP=$(cat $LASTIP) || OLDIP="" | |
if [ x"$OLDIP" = x"$NEWIP" ]; then | |
logger "No IP address change detected. Keeping $NEWIP" | |
else | |
DOMAINID=$($WGET --post-data "api_key=$APIKEY&action=domainList" | \ | |
perl -e 'if ( =~ /"DOMAIN":"'"$DOMAIN"'","DOMAINID":([0-9]+),/) { print $1; }') | |
RESOURCEID=$($WGET --post-data "api_key=$APIKEY&action=domainResourceList&DomainID=$DOMAINID" | \ | |
perl -e 'if ( =~ /"RESOURCEID":([0-9]+),"DOMAINID":'"$DOMAINID"',"TYPE":"'"$RRTYPE"'","NAME":"'"$RRNAME"'"/) { print $1; }') | |
$WGET --post-data "api_key=$APIKEY&action=domainResourceSave&ResourceID=$RESOURCEID&DomainID=$DOMAINID&Name=$RRNAME&Type=$RRTYPE&Target=$NEWIP"; echo | |
$WGET --post-data "api_key=$APIKEY&action=domainSave&DomainID=$DOMAINID&Domain=$DOMAIN&Type=master&Status=$STATUS&SOA_Email=$SOAEMAIL"; echo | |
echo $NEWIP > $LASTIP | |
logger "Updated IP address to $NEWIP" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment