Skip to content

Instantly share code, notes, and snippets.

@napcae
Created July 31, 2013 16:34
Show Gist options
  • Save napcae/6123690 to your computer and use it in GitHub Desktop.
Save napcae/6123690 to your computer and use it in GitHub Desktop.
Script to update dyndns records for digital ocean automagically.
#!/bin/bash
#WTFPL 2013 "napcae" Chi Trung Nguyen
#
#just put in your values here
#You can find the client_id and api_key in your DO dashboard
#To get the domain_id and record_id use just paste this in a browser and copy the values:
#domain_id: https://api.digitalocean.com/domains?client_id=[your_client_id]&api_key=[your_api_key]
#record_id: https://api.digitalocean.com/domains/[domain_id]/records?client_id=[your_client_id]&api_key=[your_api_key]
#see https://api.digitalocean.com/ for more information
######################################################################################################################
client_id=
api_key=
domain_id=
record_id=
externalIP=
#after that '$ crontab -e' and paste '*/15 * * * * /path/to/script', the script will update every 15 minutes
function get_externalIP {
curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z/<> :]//g' | tr -d '\r'
}
externalIP_new=$(get_externalIP)
function update_record {
curl -k "https://api.digitalocean.com/domains/"${domain_id}"/records/"${record_id}"/edit?client_id="${client_id}"&api_key="${api_key}"&data="${externalIP_new}""
}
update_record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment