Dreamhost Dynamic DNS Updater

Does anybody know how to create shell script that will allow to update the DNS? Dreamhost does have a script but don’t know how to create this, where to put the script and how it works. Can some one please help?

Thanks.

The instructions on their Wiki page for this are a little outdated (they do not include the required UUID), and I needed something like this to run on my Mac at home. I wrote the following script that should work for anyone on a Mac, or any other UNIX/Linux computer that has the curl package installed.

Add this script to a cronjob on your computer and set it to run once every hour.
0 * * * * /home/someuser/ip_updater.sh

ip_updater.sh script:

[code]#!/bin/bash

API KEY

Example: dh_api_key=ED3239DHE98J

dh_api_key=YOUR_API_KEY

DOMAIN NAME

Example: dh_domain=mydomain.com

dh_domain=YOUR_DOMAIN

DO NOT EDIT BELOW THIS LINE

uuid1=$(uuidgen)
uuid2=$(uuidgen)

dh_url=“https://api.dreamhost.com/?key=$dh_api_key&unique_id=

ip_addr=curl "http://bot.whatismyipaddress.com/"

old_ip_addr=curl "$dh_url$(uuidgen)&cmd=dns-list_records" | grep $dh_domain | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}"

dh_url_add="$dh_url$uuid1&cmd=dns-add_record&record=$dh_domain&type=A&value=$ip_addr"
dh_url_del="$dh_url$uuid2&cmd=dns-remove_record&record=$dh_domain&type=A&value=$old_ip_addr"

echo NEW IP: $ip_addr
echo OLD IP: $old_ip_addr

if [ “$ip_addr” == “$old_ip_addr” ]; then
echo SAME
else
echo DIFFERENT. UPDATING . . .
curl "$dh_url_del"
curl "$dh_url_add"
fi[/code]

cagemonkey, the UUID is optional. It’s included as a utility for applications that need to ensure that an action is not taken twice if a request is retried, but it isn’t necessary for the DNS API calls, as they’re idempotent.

Thanks, Andrew. The Wiki page for the Dreamhost API currently lists the unique_id as required. Wouldn’t you want this, though, to prevent duplicate API calls to add/remove the DNS entries?

For anyone interested in the same code with the UUID removed, here you go.

[code]#!/bin/bash

API KEY

Example: dh_api_key=ED3239DHE98J

dh_api_key=YOUR_API_KEY

DOMAIN NAME

Example: dh_domain=example.com

dh_domain=YOUR_DOMAIN

DO NOT EDIT BELOW THIS LINE

dh_url=“https://api.dreamhost.com/?key=$dh_api_key

ip_addr=curl "http://bot.whatismyipaddress.com/"

old_ip_addr=curl "$dh_url&cmd=dns-list_records" | grep $dh_domain | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}"

dh_url_add="$dh_url&cmd=dns-add_record&record=$dh_domain&type=A&value=$ip_addr"
dh_url_del="$dh_url&cmd=dns-remove_record&record=$dh_domain&type=A&value=$old_ip_addr"

echo NEW IP: $ip_addr
echo OLD IP: $old_ip_addr

if [ “$ip_addr” == “$old_ip_addr” ]; then
echo SAME
else
echo DIFFERENT. UPDATING . . .
curl "$dh_url_del"
curl "$dh_url_add"
fi[/code]