Last active
July 2, 2018 23:36
-
-
Save shashyajoshi/334bd47f68228a2a78950e2632949715 to your computer and use it in GitHub Desktop.
Script to collect OS license data from the instances
This file contains hidden or 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 | |
# Header row for the CSV output | |
echo "project_id,instance_name,license" | |
# for every project in the list get the required details. Remove CSV header from the gcloud output. Add the project id to the beginning of each row | |
for project in $(gcloud projects list --format="value(projectId)") | |
do | |
# Because of the nested structure you get ']] at the end of the output. Use sed to remove it | |
gcloud compute instances list --format="csv[no-heading](name,disks.licenses.basename())" --project $project | sed s/\']]//g | sed "s/^/$project,/" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment