-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.sh
executable file
·46 lines (37 loc) · 1.14 KB
/
delete.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Cloudflare credentials and zone information
CF_API_KEY="YOUR_API_KEY"
CF_EMAIL="YOUR_EMAIL"
CF_ZONE_ID="YOUR_ZONE_ID"
# Input arguments for record name and type
RECORD_NAME=$1
RECORD_TYPE=$2
# Cloudflare API URL for fetching and deleting DNS records
CF_API_URL="https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records"
# Function to fetch the DNS record ID
fetch_record_id() {
response=$(curl -s -X GET "$CF_API_URL?type=$RECORD_TYPE&name=$RECORD_NAME" \
-H "Authorization: $CF_API_KEY" \
-H "Content-Type: application/json")
echo $(echo $response | grep -Po '"id":"\K[^"]+')
}
# Function to delete DNS record
delete_dns_record() {
local record_id=$1
curl -s -X DELETE "$CF_API_URL/$record_id" \
-H "Authorization: $CF_API_KEY" \
-H "Content-Type: application/json"
}
# Check for correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <record name> <record type>"
exit 1
fi
# Fetch and delete the DNS record
record_id=$(fetch_record_id)
if [ -z "$record_id" ]; then
echo "Record not found."
exit 1
fi
delete_dns_record $record_id
echo "Record deleted successfully."