Last active
January 15, 2018 05:39
-
-
Save metalefty/7153d596f4976ba8bb491ac96193a86c to your computer and use it in GitHub Desktop.
Amazon Route 53 でDDNSするやつ
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/sh | |
| export LANG=C | |
| # 環境変数に AWS_ACCESS_KEY_ID と AWS_SECRET_ACCESS_KEY をセットしておく | |
| DIG="dig +noedns" | |
| CURL="curl -s" | |
| TTL=10 | |
| IP4ADDR_CUR=$(${CURL} http://checkip.amazonaws.com) | |
| RC=$? | |
| if [ $RC -ne 0 ]; then | |
| echo "failed to obtain current ip address" 1>&2 | |
| exit $RC | |
| fi | |
| IP4ADDR_DNS=$(${DIG} +short $(hostname) A) | |
| RC=$? | |
| if [ $RC -ne 0 ]; then | |
| echo "failed to resolve $(hostname)" 1>&2 | |
| exit $RC | |
| fi | |
| if [ "$IP4ADDR_CUR" != "$IP4ADDR_DNS" ]; then | |
| cli53 rc --wait --replace $(hostname -d) "$(hostname -s) ${TTL} A ${IP4ADDR_CUR}" | |
| RC=$? | |
| ${DIG} $(hostname) | |
| exit $RC | |
| else | |
| echo "there's no need to update dns:" | |
| printf %20s=%s\\n $(hostname) ${IP4ADDR_DNS} | |
| printf %20s=%s\\n checkip ${IP4ADDR_CUR} 1>&2 | |
| exit 0 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment