Last active
May 23, 2019 00:02
-
-
Save TooTallNate/04ee1a5427af0a6e2b10e0884bab8a08 to your computer and use it in GitHub Desktop.
Google Domains Dynamic DNS record update script - syncs a host to a target (pseudo-ALIAS)
This file contains 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
#!/usr/bin/env sh | |
# | |
# Usage: | |
# USERNAME=abcd12345 PASSWORD=ghij67890 HOST=n8.io TARGET=alias.zeit.co ./updater.sh | |
URL="https://domains.google.com/nic/update" | |
HOST_IP=$(dig @8.8.8.8 +short A "$HOST" | sort | tail -1) | |
TARGET_IP=$(dig @8.8.8.8 +short A "$TARGET" | sort | tail -1) | |
if [ "$HOST_IP" != "$TARGET_IP" ]; then | |
echo "Updating Dynamic DNS record for host $(tput bold)$HOST$(tput sgr0) to IP $(tput bold)$TARGET_IP$(tput sgr0)" | |
curl \ | |
--silent \ | |
--request POST \ | |
--user "$USERNAME:$PASSWORD" \ | |
--header "Content-Length: 0" \ | |
--header "User-Agent: https://git.io/v6LQz" \ | |
"$URL?hostname=$HOST&myip=$TARGET_IP" | |
echo | |
else | |
echo "Dynamic DNS for host $(tput bold)$HOST$(tput sgr0) is up-to-date!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment