1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

インスタンスタイプ毎に稼働中のインスタンスとRI数を出力するスクリプト

Last updated at Posted at 2017-03-14
#! /bin/bash
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running" --query "Reservations[].Instances[?InstanceLifecycle!=\`spot\`].[InstanceId,InstanceType]" --output text|awk -F "\t" '{a[$3$2]+=1}END{ for (i in a) print i,"\t", a[i],"\t"}'|sort > running_noaz.txt

aws ec2 describe-reserved-instances --filters "Name=state,Values=active" "Name=instance-type,Values=*" --query "ReservedInstances[].[InstanceType,InstanceCount]" --output text|awk -F "\t" '{a[$1]+=$2}END{ for (i in a) print i,"\t\t",a[i]}'|sort > reserved_noaz.txt

echo "[InstanceType] [Running] [Reserved]"

awk -F "\t" '{a[$1]+=$2;b[$1]+=$3}END{ for (i in a) print i,"\t",a[i],"\t",b[i]}' running_noaz.txt reserved_noaz.txt|sort
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?