Last active
February 4, 2019 14:40
-
-
Save zepptron/5c84853c0d3ca53874774ae71b2dbe18 to your computer and use it in GitHub Desktop.
azure get ip function => .zshrc / .bashrc
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
azure-ips () { | |
local rgp=$(az group list | jq '.[].name' | sed 's/"//g' | fzf ) | |
local check_vm=($(az vm list -g ${rgp} | jq '.[].name' | sed 's/"//g')) | |
local check_vmss=($(az vmss list -g ${rgp} | jq '.[].name' | sed 's/"//g')) | |
local array=() | |
if [[ $check_vm ]]; then array+=$check_vm fi | |
if [[ $check_vmss ]]; then array+=($check_vmss) fi | |
local count=$(echo "${#array[@]}") | |
if [[ $count > "1" ]]; then | |
local get=($(echo $array | tr ' ' '\n' | fzf)) | |
elif [[ $count == "1" ]]; then | |
local get=($(echo $array | tr ' ' '\n')) | |
else | |
echo "no VMs or VMSS found." | |
return 0 | |
fi | |
if [[ " ${check_vm[@]} " =~ " ${get} " ]]; then | |
az vm show -g ${rgp} --name ${get} -d | jq '.privateIps' | |
elif [[ " ${check_vmss[@]} " =~ " ${get} " ]]; then | |
az vmss nic list -g ${rgp} --vmss-name ${get} | jq '.[].ipConfigurations | .[].privateIpAddress' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment