google-cloud-platform - 如何使用 gcloud cli 获取操作系统类型
问题描述
我的gcp
项目中有几个实例正在运行。
所以我需要遍历每个实例并需要获取操作系统版本,如果操作系统版本匹配某个值,我需要执行另一个gcloud
命令来获取安装的库。
所以我使用这个命令来迭代每个实例:
$(gcloud compute instances list --format="value(name)")
// which gives the output as below
name: temp-1
---
name: temp-2
---
name: test1
我也需要摆脱name:
。
- 我需要使用每个实例的 linux 发行版(ubuntu、centos/rhel)
/etc/os-release
是否可以 ssh(没有真正的 ssh-ing)并awk -F= '/^NAME/{print $2}' /etc/os-release
在每个服务器(temp-1、temp-2、test1)中执行命令并将结果返回到命令行?
解决方案
我看到了几种方法来做到这一点。您可以使用以下任一命令:
$ 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 产品:
推荐阅读
- r - 如何在特定条件下粘贴带有破折号的两列
- xamarin.forms - Xamarin.Forms:列表变得比列表视图中的项目长
- python - Django嵌套重组
- java - android.app.ActivityManager.AppTask 访问静态类的非静态方法
- r - 上传文件并在闪亮中使用summarytools
- arrays - 如何使用 Laravel 将 JSON 元素保存为数据库中的记录?
- reactjs - 无法读取未定义 npm ERR 的属性“拆分”!代码生命周期
- c# - 按下 Enter 键时,具有 Janus Gridex 的 WinForm 挂起/冻结
- node.js - 配置 PollyJS 以忽略某些请求
- c# - C# 中的冗余存储或 linq 语句?