Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save banasiak/b1363d5aabdbf279db5c8f7c1bd5e1fa to your computer and use it in GitHub Desktop.
Save banasiak/b1363d5aabdbf279db5c8f7c1bd5e1fa to your computer and use it in GitHub Desktop.
Shell script to dynamically update a Digital Ocean DNS record
#!/bin/bash
TOKEN="Get token from https://cloud.digitalocean.com/settings/applications"
DOMAIN=example.com
RECORD_ID=12345
IP=`curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'`
# to get record id:
# curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records"
# update domain record
curl -s -X PUT -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -d "{\"data\":\"$IP\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment