Last active
April 30, 2023 08:07
-
-
Save francescor/aaf2bdff5ef57f92799f4e123681af2a to your computer and use it in GitHub Desktop.
List public IP and fqdn of all Azure instances belonging to a Virtual machine scale set (aka vmss) with easy ssh command to login
This file contains hidden or 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 | |
# List instances of an Azure vmss | |
# List public IP and fqdn of all Azure instances belonging to | |
# a Virtual machine scale set (aka vmss) with easy ssh command to login | |
# Gits at https://gist.github.com/francescor/aaf2bdff5ef57f92799f4e123681af2a | |
ResourceGroup="myRG" | |
VmssName="myVMSS" | |
# adapt with your username | |
# username=$USER | |
username="ubuntu" | |
echo "-----------------------------------------------------------------------------------------" | |
echo " Azure instances in vmss: $VmssName ($ResourceGroup)" | |
echo "-----------------------------------------------------------------------------------------" | |
# debug with | |
# az vmss list-instance-public-ips --name $VmssName --resource-group $ResourceGroup | jq -r '.[] | "\(.ipAddress) \t \(.dnsSettings.fqdn)" ' | |
instances=$(az vmss list-instance-public-ips --name $VmssName --resource-group $ResourceGroup | jq -r '.[] | "\(.ipAddress)|\(.dnsSettings.fqdn)" ') | |
for item in $instances; do | |
# echo $item | |
echo $item | awk -v user=$username -F'|' '{print "ssh "user"@"$1 " # "$2}' | |
done | |
echo "-----------------------------------------------------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment