Created
November 6, 2012 06:34
-
-
Save rdj/4023015 to your computer and use it in GitHub Desktop.
Bash script to use from cron to dynamically update IP on Amazon route 53
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
| #!/bin/bash | |
| source ~/.rvm/environments/default | |
| DNS_ZONE=yourdomain.com | |
| DNS_RECORD=yourhost.yourdomain.com. | |
| IP_CACHE_FILE="$(dirname $0)/update-ip.cache" | |
| if [[ -r "$IP_CACHE_FILE" ]]; then | |
| LAST_KNOWN_IP=$(< "$IP_CACHE_FILE") | |
| fi | |
| CURRENT_IP=$(curl -s http://checkip4.zerigo.com/ | perl -pe 's{<ipv4>(.*?)</ipv4>}{$1}') | |
| if [[ "$CURRENT_IP" != "$LAST_KNOWN_IP" ]]; then | |
| echo "Updating IP Address -- ${LAST_KNOWN_IP} -> ${CURRENT_IP}" | |
| route53 -g --zone "${DNS_ZONE}" --name "${DNS_RECORD}" --type A --values "${CURRENT_IP}" | |
| echo "$CURRENT_IP" > "$IP_CACHE_FILE" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment