From f3f324d4704e929726f1397607973b5dd6a25fa2 Mon Sep 17 00:00:00 2001 From: Navratan Gupta Date: Sun, 10 May 2020 15:21:56 +0530 Subject: [PATCH] TTL: goDaddy record and properties file not equal it will update the record --- debug-output.txt | 8 ++++++++ godaddyDDNS.log | 1 - godaddyDDNS.sh | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 debug-output.txt diff --git a/debug-output.txt b/debug-output.txt new file mode 100644 index 0000000..9c5ece6 --- /dev/null +++ b/debug-output.txt @@ -0,0 +1,8 @@ +result=[{"data":"103.5.135.67","name":"test","ttl":3600,"type":"A"}]' + +To filter out comments line +sudo grep -v "#" /etc/sudoers + +dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") + +existingTtl=$(echo $result | grep -oE "ttl\:[0-9]{3,}" diff --git a/godaddyDDNS.log b/godaddyDDNS.log index 0e975c1..e69de29 100644 --- a/godaddyDDNS.log +++ b/godaddyDDNS.log @@ -1 +0,0 @@ -NOT OK diff --git a/godaddyDDNS.sh b/godaddyDDNS.sh index d37e75c..95c5e9f 100755 --- a/godaddyDDNS.sh +++ b/godaddyDDNS.sh @@ -33,7 +33,10 @@ headers="Authorization: sso-key $key:$secret" result=$(curl -s -X GET -H "$headers" \ "https://api.godaddy.com/v1/domains/$domain/records/A/$name") +#echo $result + dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") +existingTtl=$(echo $result | cut -d "," -f 3 | cut -d ":" -f 2) # echo "dnsIp:" $dnsIp # Get public ip address there are several websites that can do this. @@ -41,7 +44,7 @@ ret=$(curl -s GET "http://ipinfo.io/json") currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") # echo "currentIp:" $currentIp - if [ "$dnsIp" != $currentIp ]; + if [ "$dnsIp" != $currentIp -o $existingTtl -ne $ttl ]; then # echo "Ips are not equal" request='{"data":"'$currentIp'","ttl":'$ttl'}'