<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=2634489&amp;fmt=gif">

Google Workspace, Google Cloud Strategy

Bash Script for GCP to fetch data

By Vikash Vikal | November 23, 2021

script to fetch the GCP project details as mention below.

projectid, name, projectnumber, date&time, folderpath, projectowner, folderpath, costcentre, label.

I have written belwo script and it is working for- projectid, name, projectnumber, date&time.

#!/bin/bash

> project_data.csv

gcloud projects list --format="value(project_id, name, project_number, project_owner, tag, createTime.date(tz=LOCAL))" >whole_project_details.txt

echo project_id, project_name, project_number, project_owner, project_tag, project_time >project_data.csv

while read project_details

do

project_id=`echo $project_details | awk '{print $1}'`

project_name=`echo  $project_details | awk '{print $2}'`

project_number=`echo $project_details | awk '{print $3}'`

project_time=`echo $project_details | awk '{print $4}'`

project_owner=`echo $project_details | awk '{print $5}'`

project_tag=`echo $project_details | awk '{print $6}'`

echo $project_id, $project_name, $project_number, $project_owner, $project_tag, $project_time  >> project_data.csv

done < whole_project_details.txt

 

But not able to fetch date of - owner, folderpath, label, costcentre.

 

please help me. Thank you in advance.

 

Best Answer from: sathyaram_s 


 

From the documentation : 

 

To refer to a list of fields you can sort, filter, and format by for each resource, you can run a list command with the format set to text or json. For example, $ gcloud compute instances list --limit=1 --format=text.

 

In your case, try gcloud projects list --format=text to confirm all the information you are after is available for the project resource. 


Recent Articles

Data Analytics

Generative AI: Are You Behind?!

Review the latest insights from the AI Readiness Report.
By Bruno Aziza
Industry Solutions

Make "Gen AI Work": Landscape, SLMs vs. LLMs, Cost & More...

Discover the 5 metrics you need to know in order to be an exceptional CEO and Operator.
By Bruno Aziza
Google Cloud Strategy

AI Cheat Sheet

AI is no more and no less the drive to create robots with human minds so they can do everything we do and more. Use this cheat sheet to help decode the space.
By Leah Zitter