title: optimize my bash script with gcloud commands
body: <p>Could you help me with optimizing this script for me? This is grabbing all the meta data from our total organization and currently this script takes any where between 12-13 hours to complete. But I want to run this multiple times a weeks, is there a way to optimize it and get the results faster?</p>
  <pre><code>#!/usr/bin/env bash
  PROJECTS=$(gcloud projects list --format='get(projectId)')
  FILE=&quot;instances.csv&quot;
  rm $FILE
  touch $FILE
  START_TIME=$SECONDS
  COUNTER=1
  TOTAL=0
  echo 'name,organization,space,zone,machine_type,preemptible,internal_ip,external_ip,status,service_account,project_id' &gt;&gt; $FILE
  for project_id in $PROJECTS
  do
    ((TOTAL=TOTAL+1))
  done
  for project_id in $PROJECTS
  do
    echo 'project ' $COUNTER 'of' $TOTAL
    echo $project_id
    ORG=$(gcloud projects describe $project_id --format=&quot;get(labels.organization)&quot;)
    echo $ORG
    SPACE=$(gcloud projects describe $project_id --format=&quot;get(labels.space)&quot;)
    echo $SPACE
    gcloud compute instances list --project $project_id --format=&quot;csv(
     name,
     format(&quot;$ORG&quot;,''),
     format(&quot;$SPACE&quot;, ''),
     zone.basename(),
     machineType.machine_type().basename(),
     scheduling.preemptible.yesno(yes=true, no=''),
     networkInterfaces[].networkIP.notnull().list():label=INTERNAL_IP,
     networkInterfaces[].accessConfigs[0].natIP.notnull().list():label=EXTERNAL_IP,
     status,
     serviceAccounts[0].email
    )&quot; | awk 'NR&gt;1' | sed s/$/,$project_id/ &gt;&gt; $FILE
    ((COUNTER=COUNTER+1))
    ELAPSED_TIME=$(($SECONDS - $START_TIME))
    echo 'Elapsed time -' &quot;$(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec&quot;
  done
  ELAPSED_TIME=$(($SECONDS - $START_TIME))
    echo 'Elapsed time -' &quot;$(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec&quot;
  </code></pre>