#!/bin/bash # Source the configuration file source config.conf # Create the export folder if it doesn't exist EXPORT_FOLDER="export" mkdir -p "$EXPORT_FOLDER" # Function to export DNS records export_dns_records() { local ZONE_ID=$1 local SITE_NAME=$2 # Get current date and time TIMESTAMP=$(date +"%Y%m%d_%H%M%S") # Define the output filename with timestamp OUTPUT_FILE="$EXPORT_FOLDER/${SITE_NAME}_$TIMESTAMP" # Perform the curl request and save the output curl -X GET --url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/export \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" | tee "$OUTPUT_FILE" } # Loop through the configuration entries i=1 while true; do eval "ZONE_ID=\${ZONE_ID_$i}" eval "SITE_NAME=\${SITE_NAME_$i}" # Break the loop if no more entries if [ -z "$ZONE_ID" ] || [ -z "$SITE_NAME" ]; then break fi # Export DNS records for the current entry export_dns_records "$ZONE_ID" "$SITE_NAME" # Increment the counter ((i++)) done