Last active 1741424934

lsemenenko's Avatar lsemenenko revised this gist 1741424934. Go to revision

1 file changed, 44 insertions

digitalocean_domain_bulk_delete.sh(file created)

@@ -0,0 +1,44 @@
1 + #!/bin/bash
2 +
3 + # Script to process domains from a file, validate format, check if they exist, and delete them
4 +
5 + # Check if the input file exists
6 + if [ ! -f "$1" ]; then
7 + echo "Error: Input file '$1' not found."
8 + exit 1
9 + fi
10 +
11 + # Define a regex pattern for valid domain format
12 + # This pattern checks for a basic domain format: something.something
13 + DOMAIN_PATTERN="^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9-]+)*$"
14 +
15 + # Read the file line by line
16 + while IFS= read -r domain || [ -n "$domain" ]; do
17 + # Skip empty lines
18 + if [ -z "$domain" ]; then
19 + continue
20 + fi
21 +
22 + # Check if the domain has a valid format
23 + if [[ $domain =~ $DOMAIN_PATTERN ]]; then
24 + echo "Processing valid domain: $domain"
25 +
26 + # Check if the domain exists using doctl
27 + if doctl compute domain get "$domain" &>/dev/null; then
28 + echo "Domain '$domain' exists. Deleting..."
29 +
30 + # Delete the domain
31 + if doctl compute domain delete "$domain" -f; then
32 + echo "Domain '$domain' successfully deleted."
33 + else
34 + echo "Failed to delete domain '$domain'."
35 + fi
36 + else
37 + echo "Domain '$domain' does not exist in DigitalOcean."
38 + fi
39 + else
40 + echo "Invalid domain format: $domain (skipping)"
41 + fi
42 + done < "a"
43 +
44 + echo "Domain processing complete."
Newer Older