digitalocean_domain_bulk_delete.sh
· 1.3 KiB · Bash
Sin formato
#!/bin/bash
# Script to process domains from a file, validate format, check if they exist, and delete them
# Check if the input file exists
if [ ! -f "$1" ]; then
echo "Error: Input file '$1' not found."
exit 1
fi
# Define a regex pattern for valid domain format
# This pattern checks for a basic domain format: something.something
DOMAIN_PATTERN="^[a-zA-Z0-9][a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9-]+)*$"
# Read the file line by line
while IFS= read -r domain || [ -n "$domain" ]; do
# Skip empty lines
if [ -z "$domain" ]; then
continue
fi
# Check if the domain has a valid format
if [[ $domain =~ $DOMAIN_PATTERN ]]; then
echo "Processing valid domain: $domain"
# Check if the domain exists using doctl
if doctl compute domain get "$domain" &>/dev/null; then
echo "Domain '$domain' exists. Deleting..."
# Delete the domain
if doctl compute domain delete "$domain" -f; then
echo "Domain '$domain' successfully deleted."
else
echo "Failed to delete domain '$domain'."
fi
else
echo "Domain '$domain' does not exist in DigitalOcean."
fi
else
echo "Invalid domain format: $domain (skipping)"
fi
done < "a"
echo "Domain processing complete."
| 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." |