#!/usr/bin/env bash set -euo pipefail src_dns_server=192.168.1.2 # DHCP scopes to manage - put the name of each scope you have dhcp_scopes=("local-home") # Use this array for one or many scopes echo "Checking primary Technitium server status" status_code=$(curl --write-out '%{http_code}' --silent --output /dev/null http://$src_dns_server:5380) if [[ "$status_code" -ne 200 ]]; then echo "Primary DNS/DHCP server is not available. Enabling DHCP on the secondary server." action="enable" else echo "Primary DNS/DHCP server is available. Disabling DHCP on the secondary server." action="disable" fi for scope in "${dhcp_scopes[@]}"; do echo "Executing API call to $action DHCP scope: $scope" response=$(curl -X POST "http://localhost:5380/api/dhcp/scopes/$action?token=$DNS1_API&name=$scope" \ --silent --write-out "%{http_code}") echo "HTTP response code: $response" if [[ "$response" == "200" ]]; then echo "Successfully $action DHCP for scope: $scope" else echo "Failed to $action DHCP for scope: $scope. Check the response body for details." fi done