Skip to content

Instantly share code, notes, and snippets.

@mcipekci
Created March 31, 2020 19:19
Show Gist options
  • Save mcipekci/aa6397ead8f2b632c1a1a3cbdc9a8bf0 to your computer and use it in GitHub Desktop.
Save mcipekci/aa6397ead8f2b632c1a1a3cbdc9a8bf0 to your computer and use it in GitHub Desktop.
#!/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