Created
November 2, 2021 03:12
-
-
Save blizko/5a7fc38753a8da3379762f787e606b2c to your computer and use it in GitHub Desktop.
Migrate /etc/hosts to DigitalOcean domain zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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