From 4f99eff7ae2840a9a37cf3ee542c8ddb2524f11f Mon Sep 17 00:00:00 2001 From: Jeff Billimek Date: Fri, 28 Sep 2018 20:37:09 -0400 Subject: [PATCH] only update if IP changed Signed-off-by: Jeff Billimek --- dyndns.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dyndns.sh b/dyndns.sh index a6dd4ee..61e83da 100755 --- a/dyndns.sh +++ b/dyndns.sh @@ -20,6 +20,7 @@ while ( true ); do -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ $dns_list) record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .id") + record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"@\") | .data") test -z $record_id && die "No record found with given domain name!" @@ -28,13 +29,15 @@ while ( true ); do url="$dns_list/$record_id" if [[ -n $ip ]]; then - echo "Sending data=$data to url=$url" + if [[ "$ip" != "$record_data" ]]; then + echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url" - curl -s -X PUT \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ - -d "$data" \ - "$url" &> /dev/null + curl -s -X PUT \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ + -d "$data" \ + "$url" &> /dev/null + fi else echo "IP wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." fi