Skip to content

Instantly share code, notes, and snippets.

@shashyajoshi
Last active July 2, 2018 23:36
Show Gist options
  • Save shashyajoshi/4682a1e881212f49b29a606aade3a896 to your computer and use it in GitHub Desktop.
Save shashyajoshi/4682a1e881212f49b29a606aade3a896 to your computer and use it in GitHub Desktop.
Script to collect disk user data
#!/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