#!/bin/bash echo "id,name,size,disksize,os,cpu,ram,ec2" gcloud compute instances list --filter="status=running" --format=json | jq -cr '.[] | [.id, .name, (.machineType | split("/")[10]), (.disks[] | .diskSizeGb), (.disks[] | .licenses[0] | split("/")[9]),(.zone | split("/")[8])] | @csv' > /tmp/instances.csv cat /tmp/instances.csv | while read l; do echo -n $l, INSTSIZE=$(echo $l | awk -F, '{print $3}' | tr -d \") gcloud compute machine-types describe $INSTSIZE --zone asia-northeast1-c --format json | jq -cr '[.guestCpus,.memoryMb] | @csv' done > /tmp/instances2.csv cat /tmp/instances2.csv | while read l; do echo -n $l, CPU=$(echo $l | awk -F, '{print $(NF-1)}') RAM1=$(echo $l | awk -F, '{print $NF}') RAM2=$(echo $RAM1/1024 | bc) /root/ec2-matching.sh $CPU $RAM2 done