16 lines
727 B
Bash
16 lines
727 B
Bash
#!/bin/bash
|
|
echo "InstanceName","InstanceSize","vcpu","ram","OS","InstanceId","OSVersion","Location","TotalDiskSize","MatchingEC2"
|
|
aliyuncli ecs DescribeInstances --MaxResults 100 | \
|
|
jq -cr '.Instances.Instance[] | [.InstanceName,.InstanceType,.Cpu,.Memory,.OSType,.InstanceId,.OSNameEn,.ZoneId] | @csv' \
|
|
> /tmp/instances.csv
|
|
aliyuncli ecs DescribeDisks --MaxResults 200 | jq -cr '.Disks.Disk[] | [.Size,.InstanceId] | @csv' > /tmp/disks.csv
|
|
cat /tmp/instances.csv | while read l; do
|
|
i=$(echo $l | awk -F, '{print $6}')
|
|
DISK=$(grep $i /tmp/disks.csv | awk -F, '{SUM+=$1}; END {print SUM}')
|
|
CPU=$(echo $l | awk -F, '{print $3}')
|
|
RAM=$(echo $l | awk -F, '{print $4/1024}')
|
|
echo -n "$l,$DISK,"
|
|
./ec2-matching.sh $CPU $RAM
|
|
done
|
|
|