Skip to content

Instantly share code, notes, and snippets.

@rdj
Created November 6, 2012 06:34
Show Gist options
  • Select an option

  • Save rdj/4023015 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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