【问题标题】:How to get the OS type using gcloud cli如何使用 gcloud cli 获取操作系统类型
【发布时间】:2020-11-10 15:52:28
【问题描述】:

我的gcp 项目中有几个实例正在运行。

所以我需要遍历每个实例并需要获取操作系统版本,如果操作系统版本匹配某个值,我需要执行另一个gcloud命令来获取安装的库。

所以我使用这个命令来遍历每个实例:

$(gcloud compute instances list --format="value(name)")

// which gives the output as below

name: temp-1
---
name: temp-2
---
name: test1

我也需要摆脱name:

  1. 我需要使用/etc/os-release 获取每个实例的 linux 发行版(ubuntu、centos/rhel)

是否可以在每个服务器(temp-1、temp-2、test1)中 ssh(没有真正的 ssh-ing)并执行 awk -F= '/^NAME/{print $2}' /etc/os-release 命令并将结果返回到命令行?

【问题讨论】:

    标签: google-cloud-platform gcloud


    【解决方案1】:

    我看到了几种方法来做到这一点。您可以使用以下任一命令:

    $ gcloud compute ssh --zone us-central1-a instance-1 --command "uname -a"
    Linux instance-1 4.19.0-11-cloud-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64 GNU/Linux
    
    $ gcloud compute ssh --zone us-central1-a instance-1 -- uname -a
    Linux instance-1 4.19.0-11-cloud-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64 GNU/Linux
    Connection to n.n.n.n closed.
    

    或者,您可以大规模使用 VM Manager 产品:

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多