最終更新 1741424934

digitalocean_domain_bulk_delete.sh Raw
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
6if [ ! -f "$1" ]; then
7 echo "Error: Input file '$1' not found."
8 exit 1
9fi
10
11# Define a regex pattern for valid domain format
12# This pattern checks for a basic domain format: something.something
13DOMAIN_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
16while 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
42done < "a"
43
44echo "Domain processing complete."