From cd27667d3cca530dd2a4cd0c1845c1055b3006ea Mon Sep 17 00:00:00 2001 From: Carl <155855+lord-carlos@users.noreply.github.com> Date: Wed, 27 Nov 2019 20:03:16 +0100 Subject: [PATCH] update multiple zone labels changed RECORD variable to RECORDS array. The script will go through the array one by one and update each zone label. --- bash/livedns/mywanip.sh | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bash/livedns/mywanip.sh b/bash/livedns/mywanip.sh index 548991b..a308f5b 100644 --- a/bash/livedns/mywanip.sh +++ b/bash/livedns/mywanip.sh @@ -3,15 +3,15 @@ # Updates a zone record using Gandi's LiveDNS. # Ideally this script is placed into a crontab or when the WAN interface comes up. # Replace APIKEY with your Gandi API Key and DOMAIN with your domain name at Gandi. -# Set RECORD to which zone label you wish to update. -# You will be able to query mywanip.example.net if everything went successful. +# Set RECORDS to which zone labels you wish to update. +# You will be able to query example.net, mywanip.example.net and mywanip2.example.net if everything went successful. # # Live dns is available on www.gandi.net # Obtaining your API Key: http://doc.livedns.gandi.net/#step-1-get-your-api-key # DOMAIN="example.net" -RECORD="mywanip" +RECORDS=( "@" "mywanip" "mywanip2" ) APIKEY="my-api-key" @@ -27,19 +27,22 @@ if [[ -z "$IP4" && -z "$IP6" ]]; then fi -if [[ ! -z "$IP4" ]]; then - DATA='{"rrset_values": ["'$IP4'"]}' - curl -s -XPUT -d "$DATA" \ - -H"X-Api-Key: $APIKEY" \ - -H"Content-Type: application/json" \ - "$API/domains/$DOMAIN/records/$RECORD/A" -fi - -if [[ ! -z "$IP6" ]]; then - DATA='{"rrset_values": ["'$IP6'"]}' - curl -s -XPUT -d "$DATA" \ - -H"X-Api-Key: $APIKEY" \ - -H"Content-Type: application/json" \ - "$API/domains/$DOMAIN/records/$RECORD/AAAA" -fi +for RECORD in "${RECORDS[@]}" +do + if [[ ! -z "$IP4" ]]; then + DATA='{"rrset_values": ["'$IP4'"]}' + curl -s -XPUT -d "$DATA" \ + -H"X-Api-Key: $APIKEY" \ + -H"Content-Type: application/json" \ + "$API/domains/$DOMAIN/records/$RECORD/A" + fi + + if [[ ! -z "$IP6" ]]; then + DATA='{"rrset_values": ["'$IP6'"]}' + curl -s -XPUT -d "$DATA" \ + -H"X-Api-Key: $APIKEY" \ + -H"Content-Type: application/json" \ + "$API/domains/$DOMAIN/records/$RECORD/AAAA" + fi +done