0

i need count total number of aws instances in all region and I write this script:

#!/bin/bash
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
      aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --region $region --output text | wc -l
done

The output is like this:

...
0
0
0
48
0
0
0
...

Is there a way to get the total of these values?

1 Answer 1

1

Try the following

#!/bin/bash
SUM=0
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do
      I="$(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --region $region --output text | wc -l)"
      let SUM=SUM+I
done

echo "$SUM"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.