Last active
April 17, 2023 10:15
-
-
Save rajathithan/3cd858198cafef22f684a9cb42ad4dcd to your computer and use it in GitHub Desktop.
compute-engine-details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to retrieve compute engine details. | |
# Author - Rajathithan Rajasekar - 03/03/2020 | |
echo "PROJECT NAME, INSTANCE NAME , ZONE , MACHINE-TYPE , OPERATING SYSTEM , CPU , MEMORY , DISK SIZE" > compute-engine-details.csv | |
prjs=( $(gcloud projects list | tail -n +2 | awk {'print $1'}) ) | |
for i in "${prjs[@]}" | |
do | |
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" >> list.txt | |
echo "Setting Project: $i" >> list.txt | |
echo $(gcloud config set project $i) | |
if [[ $(gcloud services list --enabled --filter="NAME:compute.googleapis.com" --format="value(NAME)" | grep compute) ]]; then | |
echo "Compute API is enabled is in project - $i" | |
echo $(gcloud compute instances list | awk '{print $1,$2}' | tail -n +2| while read line; do echo "$i $line"; done |xargs -n3 sh -c 'python3 retrieve-compute-engine-details.py $1 $2 $3 >> compute-engine-details.csv' sh) | |
else | |
echo "Compute API is not enabled in project - $i" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While trying to execute the script, I'm getting the below: