From f6f491f3430656be370fdf058b8e8629203ddea6 Mon Sep 17 00:00:00 2001 From: x p k Date: Wed, 14 Dec 2022 19:38:29 +0800 Subject: [PATCH] UPD: grouping sqls --- aws/cost-optimization.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/aws/cost-optimization.sh b/aws/cost-optimization.sh index 8f59886..f34d992 100755 --- a/aws/cost-optimization.sh +++ b/aws/cost-optimization.sh @@ -8,15 +8,14 @@ sqlite3 co.db 'create table instances(type varchar(20),running int, ri int);' # Count instance types in region echo "Getting list of Ec2 instances..." aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceType' --filter Name=instance-state-name,Values=running --output text | tr '\t' '\n' | sort | uniq -c | while read count type; do -sqlite3 co.db "insert into instances values(\"$type\", \"$count\",0);" -done + echo "insert into instances values(\"$type\", $count,0);" +done | sqlite3 co.db # List RI in region echo "Getting list of RI..." aws ec2 describe-reserved-instances --query ReservedInstances[].[InstanceCount,InstanceType] --output text | while read count type; do - # echo sqlite3 co.db "update instances set ri = \"$count\" where type = \"$type\";" - sqlite3 co.db "update instances set ri = \"$count\" where type = \"$type\";" -done + echo "update instances set ri = $count where type = \"$type\";" +done | sqlite3 co.db # List ISP echo "Getting ISP..."