谷歌云项目格式--labelling

时间:2021-03-17 04:09:21

标签: google-cloud-platform gcp-ai-platform-training

下面是我的脚本,它在 gcp 中打印名称、项目 ID、组织、空间、区域。我很确定其他部分很好,但在 --> format("$ORG", ''),format("$SPACE", '') 中出错,因为并非所有项目都有组织、空间并且它们是空的。当它们为空时如何通过设置为 N/A 来修复它。

  `echo 'project ' $COUNTER 'of' $TOTAL
  echo $project_id
  ORG=$(gcloud projects describe $project_id --format="get(labels.organization)")
  echo $ORG
  SPACE=$(gcloud projects describe $project_id --format="get(labels.space)")
  echo $SPACE
  gcloud compute instances list --project $project_id --format="csv(
   name,
   format("$ORG", ''),
   format("$SPACE", ''),
   zone.basename()
)" | awk 'NR>1' | sed s/$/,$project_id/
   >> $FILE

1 个答案:

答案 0 :(得分:0)

试试这个:

`echo 'project ' $COUNTER 'of' $TOTAL
echo $project_id
ORG=$(gcloud projects describe project_id --format="get(labels.organization)")
if [ -z "$ORG" ]
then
        ORG="N/A"
fi
echo $ORG
SPACE=$(gcloud projects describe project_id --format="get(labels.space)")
if [ -z "$SPACE" ]
then
        SPACE="N/A"
fi
echo $SPACE
gcloud compute instances list --project $project_id --format="csv(
   name,
   format("$ORG", ''),
   format("$SPACE", ''),
   zone.basename()
)" | awk 'NR>1' | sed s/$/,$project_id/
   >> $FILE