Skip to content

Instantly share code, notes, and snippets.

@cwleonard
Created September 19, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwleonard/2a13fd341a2246ec6ffa5df7aab5b6fc to your computer and use it in GitHub Desktop.
Save cwleonard/2a13fd341a2246ec6ffa5df7aab5b6fc to your computer and use it in GitHub Desktop.
dynamically set a GoDaddy DNS record
#!/bin/bash
domain="example.com"
aname="subdomain"
key="your_key"
secret="your_secret"
myip=`curl -s -X GET http://api.ipify.org?format=json | jq -r .ip`
recip=`curl -s -X GET "https://api.godaddy.com/v1/domains/$domain/records/A/$aname" -H "accept: application/json" -H "Authorization: sso-key $key:$secret" | jq -r .[0].data`
echo "my ip is $myip"
echo "A rec is $recip"
if [ "$myip" != "$recip" ]; then
echo "ip does not match"
newdata="[{\"data\":\"$myip\",\"ttl\":600}]"
echo "new data is: $newdata"
curl -s -X PUT "https://api.godaddy.com/v1/domains/$domain/records/A/$aname" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: sso-key $key:$secret" -d "$newdata"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment