Last active
May 30, 2025 03:37
-
-
Save cipulan/4498e2f2bdc23e20f8ed1152e32d31f5 to your computer and use it in GitHub Desktop.
Bulk Remove Zone Record Domain cPanel or WHM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
record1.domain.com | |
record2.domain.com | |
recordx.domain.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :
remove_zone_records.sh
List the domains (without wildcard) you want to remove records for, one domain per line. Example:
The script will automatically:
✅ Remove DNS zone records for each domain in the list
✅ Remove matching wildcard DNS records (e.g., *.domain.com.)