From 7dc3c69a28a1dec3e3e8032a4a7ec580264e08a6 Mon Sep 17 00:00:00 2001 From: Navratan Gupta Date: Mon, 6 Jul 2020 13:57:44 +0530 Subject: [PATCH] Resolved: ./godaddyDDNS.sh: line 42: [: []: integer expression expected --- godaddyDDNS.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/godaddyDDNS.sh b/godaddyDDNS.sh index 1ab68d4..58b37a8 100755 --- a/godaddyDDNS.sh +++ b/godaddyDDNS.sh @@ -34,6 +34,8 @@ result=$(curl -s -X GET -H "$headers" \ 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) +# If record is not created ttl value to initialise with a number +[[ "$existingTtl" == "[]" ]] && existingTtl=0 # Get public ip address there are several websites that can do this. ret=$(curl -s GET "http://ipinfo.io/json") @@ -48,8 +50,8 @@ currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b") -H "Content-Type: application/json" \ -d [$request] "https://api.godaddy.com/v1/domains/$domain/records/A/$name") # Fetch out status from output and REMOVES \r character which is automatically getting suffixed in output of API - result=$(echo "$nresult" | grep -i http | awk '{first=$1;$1="";print $0;first;}' | awk '{print $NF}'|sed 's/\r$//') - #res=$(echo $result|awk '{print $NF}'|sed 's/\r$//') + result=$(echo "$nresult" | grep -i http | awk '{first=$1;$1="";print $0;first;}') + res=$(echo $result|awk '{print $NF}'|sed 's/\r$//') if [[ "$res" == "OK" ]] then # If status of returned output is OK