Skip to content

Instantly share code, notes, and snippets.

@disusered
Created November 11, 2013 00:20
Show Gist options
  • Save disusered/7405821 to your computer and use it in GitHub Desktop.
Save disusered/7405821 to your computer and use it in GitHub Desktop.
Update DNSimple with local IP
#!/bin/bash
# JSON Parser
JSON=`curl -s -X GET http://jsonip.com/`
PROP='ip'
function jsonval {
temp=`echo $JSON | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $PROP`
echo ${temp##*|}
}
# Dnsimple values
REQUEST_IP=`jsonval`
TOKEN_TYPE="X-DNSimple-Domain-Token"
TOKEN="<TOKEN>"
DOMAIN_ID="<DOMAIN>"
curl -H "${TOKEN_TYPE}: ${TOKEN}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-X PUT \
-d "{\"record\": {\"content\": \"${REQUEST_IP}\"} }" \
https://dnsimple.com/domains/:domain/records/${DOMAIN_ID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment