Skip to content

Instantly share code, notes, and snippets.

@blizko
Created November 2, 2021 03:12
Show Gist options
  • Select an option

  • Save blizko/5a7fc38753a8da3379762f787e606b2c to your computer and use it in GitHub Desktop.

Select an option

Save blizko/5a7fc38753a8da3379762f787e606b2c to your computer and use it in GitHub Desktop.
Migrate /etc/hosts to DigitalOcean domain zone
while IFS= read -r i
do
host=$(echo "$i" | awk {'print $2'} | sed -e "s/.$DOMAIN//");
ip=$(echo "$i" | awk {'print $1'});
payload="{\"type\":\"A\",\"name\":\"$host\",\"data\":\"$ip\",\"priority\":null,\"port\":null,\"ttl\":3600,\"weight\":null,\"flags\":null,\"tag\":null}"
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d "$payload" \
"https://api.digitalocean.com/v2/domains/$DOMAIN/records"
done < <(cat /etc/hosts | grep "$DOMAIN")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment