Bulk Delete cPanel Subdomains by Matching String

Warning: this is a dangerous script, that deletes in bulk, matching string subdomains from a cpanel account.

It is designed as one liner.

read -p "Enter cPanel username: " acct; read -p "Enter subdomain filter (string to match): " filter; subs=$(uapi --output=json --user="$acct" DomainInfo list_domains | jq -r --arg f "$filter" '.result.data.sub_domains[] | select(contains($f))'); if [[ -z "$subs" ]]; then echo "No subdomains matching the filter."; else echo "Subdomains to delete:"; echo "$subs"; read -p "Proceed with deletion? (Y/N): " confirm; if [[ "$confirm" =~ ^[Yy]$ ]]; then for s in $subs; do echo "Deleting $s..."; whmapi1 delete_domain domain="$s"; done; else echo "Aborted."; fi; fi