@@ -25,26 +25,37 @@ source ./config.sh
25
25
# Set the subscription
26
26
az account set --name $SUBSCRIPTION_NAME
27
27
28
- delete-records () {
29
- # Get the list of record sets to delete
30
- record_sets=($( az network dns record-set list \
28
+ RECORD_SETS=()
29
+
30
+ # Find the records that end with the specified keyword
31
+ find-records () {
32
+ # Filtering to only return the records that end exactly with the specified keyword
33
+ for record in " $( az network dns record-set list \
31
34
--resource-group $RESOURCE_GROUP_NAME \
32
- --zone-name $DNS_ZONE_NAME | grep name | grep ${KEYWORD} | awk ' {print $2}' | sed ' s/"//g' | sed ' s/,//g' ) )
33
- echo $record_sets
34
- if [ ${# record_sets[*]} -gt 0 ]; then
35
+ --zone-name $DNS_ZONE_NAME | grep -o ' "name": "[^"]*"' | \
36
+ grep " ${KEYWORD} " | \
37
+ awk -F' "' ' {print $4}' ) " ; do
38
+ if [[ " $record " == * ${KEYWORD} ]]; then
39
+ RECORD_SETS+=(" $record " )
40
+ fi
41
+ done
42
+ }
43
+
44
+ delete-records () {
45
+ if [ ${# RECORD_SETS[*]} -gt 0 ]; then
35
46
echo " The following list of records will be deleted:"
36
- echo ${record_sets [*]}
47
+ echo ${RECORD_SETS [*]}
37
48
echo " Are you sure you want to perform this operation? (y/n):"
38
49
read confirm
39
50
else
40
51
echo " No records found."
41
52
abort
42
53
fi
43
54
44
- if [ ${# record_sets [*]} -gt 0 ] && [ $confirm == ' y' ]; then
55
+ if [ ${# RECORD_SETS [*]} -gt 0 ] && [ $confirm == ' y' ]; then
45
56
for type in " ${RECORD_TYPES[@]} " ; do
46
57
# Delete the record sets.
47
- for record_set in " ${record_sets [@]} " ; do
58
+ for record_set in " ${RECORD_SETS [@]} " ; do
48
59
echo " az network dns record-set $type delete \
49
60
--name " $record_set " \
50
61
--zone-name " $DNS_ZONE_NAME " \
@@ -62,6 +73,8 @@ delete-records () {
62
73
fi
63
74
}
64
75
76
+ find-records
77
+
65
78
deleted () {
66
79
# Print a success message.
67
80
echo " Successfully deleted the DNS record sets."
0 commit comments