Created
August 22, 2020 14:40
-
-
Save hute37/637cb671a624b76cc71acf015cd09986 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 | |
## | |
# Microsoft Azure: show active VM via curl | |
# | |
# Azure OAUTH HOWTO from: | |
# - https://medium.com/@mauridb/calling-azure-rest-api-via-curl-eb10a06127 | |
# | |
AR=0; \ | |
export ar_subid=$(az account list | jq ".[] | select (.isDefault == true) | .id" -r) ;\ | |
export ar_response=$(az account get-access-token) ;\ | |
export ar_token=$(echo $ar_response | jq ".accessToken" -r) ;\ | |
env | grep '^ar_' | |
AR=1 ;\ | |
curl -X GET \ | |
-H "Authorization: Bearer $ar_token" \ | |
-H "Content-Type:application/json" \ | |
-H "Accept:application/json" \ | |
https://management.azure.com/subscriptions/${ar_subid}/providers/Microsoft.Compute/virtualMachines\?api-version\=2019-12-01\&statusOnly\=true \ | |
2>/dev/null \ | |
| jq '[ .value[] | { name:.name, status:.properties.instanceView.statuses[1].displayStatus } | select(.status != "VM deallocated") ] | .[].name' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment