Skip to content

Instantly share code, notes, and snippets.

@cipulan
Last active May 30, 2025 03:37
Show Gist options
  • Save cipulan/4498e2f2bdc23e20f8ed1152e32d31f5 to your computer and use it in GitHub Desktop.
Save cipulan/4498e2f2bdc23e20f8ed1152e32d31f5 to your computer and use it in GitHub Desktop.
Bulk Remove Zone Record Domain cPanel or WHM
#!/bin/bash
# File containing the list of domain names (one per line)
DOMAIN_FILE="domains.txt"
ZONE="domain.name" #example: domainx.com
# Function to remove records for a domain and its wildcard entry
remove_specific_record() {
local domain_name=$1
echo "Processing domain: $domain_name in zone: $ZONE"
# Fully-qualified names for search
fqdn="${domain_name}."
wildcard_fqdn="*.${domain_name}."
# Find line numbers for the domain record and its wildcard variant
line_numbers=$(whmapi1 --output=jsonpretty dumpzone domain="$ZONE" \
| jq -r --arg fqdn "$fqdn" --arg wildcard "$wildcard_fqdn" '
.data.zone[].record[]
| select(.name == $fqdn or .name == $wildcard)
| .Line')
if [[ -z "$line_numbers" ]]; then
echo "No records found for $domain_name (or its wildcard) in zone $ZONE"
return
fi
# Remove each zone record line
for line in $line_numbers; do
echo "Removing line $line for $domain_name (or its wildcard) in zone $ZONE"
whmapi1 --output=jsonpretty removezonerecord zone="$ZONE" line="$line"
done
}
# Read domains from file and process each one
while IFS= read -r domain || [[ -n "$domain" ]]; do
remove_specific_record "$domain"
done < "$DOMAIN_FILE"
record1.domain.com
record2.domain.com
recordx.domain.com
@cipulan
Copy link
Author

cipulan commented May 30, 2025

Bulk Remove Zone Record Domain cPanel or WHM

This bash script removes DNS zone records for a list of domain names and their wildcard variants within the id.or.id DNS zone using the cPanel whmapi1 API.

For each domain in the domains.txt file, it deletes matching DNS records for:
• The exact domain (e.g., domain.com.)
• The wildcard version (e.g., *.domain.com.)

Usage :

  1. Save the script as remove_zone_records.sh
  2. Make it executable
chmod +x remove_zone_records.sh
  1. Create domains.txt
    List the domains (without wildcard) you want to remove records for, one domain per line. Example:
record1.domain.com
record2.domain.com
recordx.domain.com
  1. Run the script
./remove_zone_records.sh

The script will automatically:
✅ Remove DNS zone records for each domain in the list
✅ Remove matching wildcard DNS records (e.g., *.domain.com.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment