Jananath Jayarathna
Jananath Jayarathna

Reputation: 209

How to get the OS type using gcloud cli

I have couple of instances running in my gcp project.

So I need to iterate over each instance and need to get the os version, and if the os version matches a certain value, i need to execute another gcloud command to get the installed libraries.

So I am using this command to iterate over the each instance:

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

// which gives the output as below

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

I need to get rid of name: as well.

  1. And I need to get the linux distro (ubuntu, centos/rhel) of each instance using /etc/os-release

Is it possible to ssh (without really ssh-ing) and execute the awk -F= '/^NAME/{print $2}' /etc/os-release command in each server (temp-1, temp-2, test1) and get back the result to the command line?

Upvotes: 0

Views: 1964

Answers (1)

sathishvj
sathishvj

Reputation: 1464

I'm seeing a couple of ways to do this. You can use either of the following commands:

$ 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.

Alternatively, at scale, you can use the VM Manager product:

Upvotes: 1

Related Questions