From 9f088db3a632cea3ce905ed0e226e8f19fc7ae12 Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 21 Apr 2022 18:43:58 +0200 Subject: [PATCH] add error check for false or missing DNS Zone --- ddns4.sh | 7 ++++++- ddns6.sh | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ddns4.sh b/ddns4.sh index ecdc729..34dfc47 100755 --- a/ddns4.sh +++ b/ddns4.sh @@ -68,7 +68,12 @@ fi ############################################# echo -e "${PENDING} get Zones" HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE\") | .id") -echo -e "${REPLACE}${SUCCESS} get DNS Zone" +if [ -z $HETZNER_API_ZONE ]; then + echo -e "${REPLACE}${ERROR} get DNS Zone" + exit 1 +else + echo -e "${REPLACE}${SUCCESS} get DNS Zone" +fi ############################################# echo -e "${PENDING} Check DNS Console for existing records" RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \ diff --git a/ddns6.sh b/ddns6.sh index 4aa08e2..65f6dee 100755 --- a/ddns6.sh +++ b/ddns6.sh @@ -68,7 +68,12 @@ fi ############################################# echo -e "${PENDING} get Zones" HETZNER_API_ZONE=$(curl -s "https://dns.hetzner.com/api/v1/zones" -H "Auth-API-Token: ${HETZNER_API_TOKEN}" | jq -r ".zones[] | select(.name==\"$DNSZONE\") | .id") -echo -e "${REPLACE}${SUCCESS} get DNS Zone" +if [ -z $HETZNER_API_ZONE ]; then + echo -e "${REPLACE}${ERROR} get DNS Zone" + exit 1 +else + echo -e "${REPLACE}${SUCCESS} get DNS Zone" +fi ############################################# echo -e "${PENDING} Check DNS Console for existing records" RECORDS=$(curl -s "https://dns.hetzner.com/api/v1/records?zone_id=${HETZNER_API_ZONE}" \