Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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