From 08c1792ab0a22e7c5788509feb5314012b3514c3 Mon Sep 17 00:00:00 2001 From: mokainos Date: Mon, 25 Sep 2023 14:28:33 +0100 Subject: [PATCH] update --- scripts/vm/auto-shutdown.sh | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/scripts/vm/auto-shutdown.sh b/scripts/vm/auto-shutdown.sh index 8da03116..09bb1f64 100755 --- a/scripts/vm/auto-shutdown.sh +++ b/scripts/vm/auto-shutdown.sh @@ -28,7 +28,7 @@ while read subcription; do else business_area="CFT" fi - echo -e "${RED}---------------------------------------------------" + while read id; do business_area_entry=$(jq -r '."business_area"' <<<$id) env_entry=$(jq -r '."environment"' <<<$id) @@ -60,7 +60,7 @@ while read subcription; do continue fi done < <(jq -c '.[]' issues_list.json) - echo SKIP: $SKIP SKIP_HUB: $SKIP_HUB + if [[ $SKIP == "false" ]]; then echo "Stopping VM in Subscription: $SUBSCRIPTION_NAME ResourceGroup: $rg Name: $name" az vm deallocate --ids $app_id --no-wait || echo Ignoring errors Stopping VM @@ -85,16 +85,4 @@ if [[ $SKIP_HUB == "false" ]]; then az vm deallocate --ids $app_id --no-wait || echo Ignoring errors Stopping VM done fi -jq -c '.[]' <<<$SUBSCRIPTIONS | while read subcription; do - SUBSCRIPTION_ID=$(jq -r '.id' <<<$subcription) - SUBSCRIPTION_NAME=$(jq -r '.name' <<<$subcription) - az account set -s $SUBSCRIPTION_ID - ENV=$(echo $SUBSCRIPTION_NAME | awk -F "-" '{print $NF}') - echo $SUBSCRIPTION_NAME $ENV - VMS=$(az resource list --resource-type Microsoft.Compute/virtualMachines --query "[?tags.autoShutdown == 'true']" -o json) - jq -c '.[]' <<<$VMS | while read vm; do - ID=$(jq -r '.id' <<<$vm) - echo "Stopping VM in Subscription: $(az account show --query name) ResourceGroup: $(jq -r '.resourceGroup' <<<$vm) Name: $(jq -r '.name' <<<$vm)" - az vm deallocate --ids $ID --no-wait || echo Ignoring errors Stopping VM - done -done +