Last active
July 2, 2018 23:36
-
-
Save shashyajoshi/4682a1e881212f49b29a606aade3a896 to your computer and use it in GitHub Desktop.
Script to collect disk user data
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,disk_name,user" | |
# 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 disks list --format="csv[no-heading](name,users.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