From 102c2f9c9b47696542896799be6c80e1a25209be Mon Sep 17 00:00:00 2001 From: x p k Date: Tue, 18 Jul 2023 19:34:50 +0800 Subject: [PATCH] UPD: replaced for loop with parallel --- aws/aws-inventory2.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/aws/aws-inventory2.sh b/aws/aws-inventory2.sh index aaf83e5..8741d9d 100755 --- a/aws/aws-inventory2.sh +++ b/aws/aws-inventory2.sh @@ -4,7 +4,7 @@ function list-resources-in-region { export AWS_DEFAULT_REGION=$1 echo "---" - echo "# Region: $r" + echo "# Region: $1" echo "---" echo -e "\n## EC2:" aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress]' --output json | jq -cr '.[][] | @tsv' | tr -d '[\" ' @@ -41,12 +41,14 @@ function list-resources-in-region { } # Generate inventory of ec2, rds, lb, and s3 buckets. -aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do - list-resources-in-region $r > /tmp/aws-inventory-$r.txt & -done +export -f list-resources-in-region +aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | parallel list-resources-in-region {} +#aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do +# list-resources-in-region $r > /tmp/aws-inventory-$r.txt & +#done -echo "This may take a moment..." -sleep 50 +# echo "This may take a moment..." +# sleep 50 -cat /tmp/aws-inventory*.txt -rm -f /tmp/aws-inventory*.txt +#cat /tmp/aws-inventory*.txt +#rm -f /tmp/aws-inventory*.txt