redirect output to /dev/null

This commit is contained in:
Matthew Saunders Brown 2022-01-29 11:54:12 -08:00
parent 36ddcca14b
commit 4375c6bd9e
5 changed files with 12 additions and 21 deletions

View File

@ -57,7 +57,7 @@ if [[ -z $type ]]; then
fi
# first query to see if zone already exists
zone_status=$(/usr/bin/curl --silent --output /tmp/$zone --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone")
zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone?rrsets=false")
if [[ $zone_status = 200 ]]; then
# verified zone exists, delete record
@ -65,7 +65,7 @@ if [[ $zone_status = 200 ]]; then
data="{\"rrsets\":[{\"name\":\"$name\",\"type\":\"$type\",\"changetype\":\"DELETE\",\"records\":[]}]}"
# delete record(s)
zone_status=$(/usr/bin/curl --silent --request PATCH --output "/tmp/$zone" --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones/$zone")
zone_status=$(/usr/bin/curl --silent --request PATCH --output /dev/null --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones/$zone")
if [[ $zone_status = 204 ]]; then
echo "Success. Record(s) for $zone deleted."
@ -78,5 +78,3 @@ elif [[ $zone_status = 404 ]]; then
else
echo "Unexpected http response checking for Zone $zone: $zone_status"
fi
rm /tmp/$zone

View File

@ -82,7 +82,7 @@ if [[ -z $ttl ]]; then
fi
# first query to see if zone already exists
zone_status=$(/usr/bin/curl --silent --output /tmp/$zone --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone")
zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone?rrsets=false")
if [[ $zone_status = 200 ]]; then
# verified zone exists, add record(s)
@ -146,7 +146,7 @@ if [[ $zone_status = 200 ]]; then
data="$data}]}"
# add record(s)
zone_status=$(/usr/bin/curl --silent --request PATCH --output "/tmp/$zone" --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones/$zone")
zone_status=$(/usr/bin/curl --silent --request PATCH --output /dev/null --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones/$zone")
if [[ $zone_status = 204 ]]; then
echo "Success. Record(s) for $zone created/updated."
@ -161,5 +161,3 @@ elif [[ $zone_status = 404 ]]; then
else
echo "Unexpected http response checking for Zone $zone: $zone_status"
fi
rm /tmp/$zone

View File

@ -32,7 +32,7 @@ if [[ -z $zone ]]; then
fi
# first query to see if zone already exists
zone_status=$(/usr/bin/curl --silent --output /tmp/$zone.output --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone")
zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" -H "X-API-Key: $api_key" "$api_base_url/zones/$zone?rrsets=false")
if [[ $zone_status = 200 ]]; then
echo Zone $zone already exists.
@ -145,7 +145,7 @@ elif [[ $zone_status = 404 ]]; then
data="$data]}"
# add zone
zone_status=$(/usr/bin/curl --silent --request POST --output "/tmp/$zone.output" --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones")
zone_status=$(/usr/bin/curl --silent --request POST --output /dev/null --write-out "%{http_code}" --header "X-API-Key: $api_key" --data "$data" "$api_base_url/zones")
if [[ $zone_status = 201 ]]; then
echo Success. Zone $zone created.
@ -156,5 +156,3 @@ elif [[ $zone_status = 404 ]]; then
else
echo Unexpected http response checking for Zone $zone: $zone_status
fi
rm /tmp/$zone.output

View File

@ -30,9 +30,7 @@ fi
if [[ -n $execute ]] || pdns::yesno "Delete $zone now?"; then
echo
zone_status=$(/usr/bin/curl --silent --output /tmp/$zone --write-out "%{http_code}" --request DELETE --header "X-API-Key: $api_key" $api_base_url/zones/$zone)
rm /tmp/$zone
zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" --request DELETE --header "X-API-Key: $api_key" $api_base_url/zones/$zone)
if [[ $zone_status = 204 ]]; then
echo Zone $zone deleted.
elif [[ $zone_status = 404 ]]; then

View File

@ -27,21 +27,20 @@ if [[ -z $zone ]]; then
exit
fi
TMPDIR=$(mktemp -d -p /tmp)
tmpfile=$(mktemp)
# export zone and check http status
zone_status=$(/usr/bin/curl --silent --output "$TMPDIR/$zone" --write-out "%{http_code}" -H "X-API-Key: $api_key" $api_base_url/zones/$zone/export)
zone_status=$(/usr/bin/curl --silent --output "$tmpfile" --write-out "%{http_code}" -H "X-API-Key: $api_key" $api_base_url/zones/$zone/export)
if [[ $zone_status = 200 ]]; then
# return zone level records
sed -e 's/\t/|/g' $TMPDIR/$zone|column -t -s \| |grep ^$zone.
sed -e 's/\t/|/g' $tmpfile|column -t -s \| |grep ^$zone.
# return subdomain records
sed -e 's/\t/|/g' $TMPDIR/$zone|column -t -s \| |grep -v ^$zone.
sed -e 's/\t/|/g' $tmpfile|column -t -s \| |grep -v ^$zone.
elif [[ $zone_status = 404 ]]; then
echo 404 Not Found, $zone does not exist
else
echo Unexecpted http response checking for existence of zone $zone: $zone_status
fi
rm $TMPDIR/$zone
rmdir $TMPDIR
rm $tmpfile