Skip to content

Instantly share code, notes, and snippets.

@francescor
Last active April 30, 2023 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francescor/aaf2bdff5ef57f92799f4e123681af2a to your computer and use it in GitHub Desktop.
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
#! /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