Skip to content

Instantly share code, notes, and snippets.

@rdj
Created October 24, 2011 22:47
Show Gist options
  • Save rdj/1310601 to your computer and use it in GitHub Desktop.
Save rdj/1310601 to your computer and use it in GitHub Desktop.
Dynamic DNS with Zerigo and a cron job
#!/bin/bash
# Run `crontab -e` and add this line:
# */1 * * * * /Users/youraccount/bin/update-ip
# Enable API access under Zerigo's DNS / Preferences / API Access and Dynamic Updates
# Then get your API key from that same page after you save the form.
ZERIGO_HOSTNAME=host.example.com
ZERIGO_USERNAME=email%40gmail.com
ZERIGO_API_KEY=BiGrAnDoMkEyGoEsHeRe
IP_CACHE_FILE="$(dirname $0)/update-ip.cache"
if [[ -r "$IP_CACHE_FILE" ]]; then
LAST_KNOWN_IP=$(< "$IP_CACHE_FILE")
fi
CURRENT_IP=$(curl -s http://checkip4.zerigo.com/ | perl -pe 's{<ipv4>(.*?)</ipv4>}{$1}')
if [[ "$CURRENT_IP" != "$LAST_KNOWN_IP" ]]; then
echo "Updating IP Address -- ${LAST_KNOWN_IP} -> ${CURRENT_IP}"
curl -s "http://update.zerigo.com/dynamic?host=${ZERIGO_HOSTNAME}&user=${ZERIGO_USERNAME}&password=${ZERIGO_API_KEY}"
echo "$CURRENT_IP" > "$IP_CACHE_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment