Created
March 31, 2020 19:19
-
-
Save mcipekci/aa6397ead8f2b632c1a1a3cbdc9a8bf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "--------------------------------------" | |
echo "Trying to takeover $1 on Azure TrafficManager" | |
domainName=$1.trafficmanager.net | |
echo "Checking DNS state for $domainName" | |
dnsState=$(dig $domainName @tm2.msft.net | grep NXDOMAIN) | |
if [[ ! -z $dnsState ]]; then | |
echo "$1 is pointing NXDOMAIN, trying to create it..." | |
NEW_UUID=$(echo $1 | sed 's/\.//g') | |
result=$(azure network traffic-manager profile create --name $NEW_UUID -d $domainName -m Performance -p http -p https -r "/" --json 2>/dev/null | jq .profile.domainName | sed 's/\"//g') | |
if [[ -z $result ]]; then | |
echo -e "\e[2;31m$domainName exists on Azure can not takeover it\e[0m" | |
else | |
if [[ $result == $domainName ]]; then | |
echo -e "\e[1;32m$domainName created, takeover is successful\e[0m" | |
echo $domainName >> TakenOver-TrafficManagers.txt | |
else | |
echo -e "\e[2;31m$domainName exists on Azure can not takeover it\e[0m" | |
fi | |
fi | |
else | |
echo "$1 is still active on Azure..." | |
fi | |
echo "--------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment