Skip to content

Instantly share code, notes, and snippets.

@kenmickles
Last active April 11, 2022 19:47
Show Gist options
  • Save kenmickles/6746968 to your computer and use it in GitHub Desktop.
Save kenmickles/6746968 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