dgaviola
dgaviola

Reputation: 2469

gcloud ssh and commands with parameters

I'm having issues trying to execute a command over ssh using gcloud. This works perfectly when I execute from my Mac:

gcloud compute ssh instanceName --command="cd /folder; ls"

However, when I try to run that from Ubuntu inside one of the VMs, I get the following error:

ERROR: (gcloud.compute.ssh) unrecognized arguments: /folder; ls

Sounds like it is splitting the command by spaces. I tried different options like using single quotes, use vars, etc., but nothing worked for me.

What is the correct way to do it?

Upvotes: 3

Views: 3218

Answers (2)

Duke79
Duke79

Reputation: 927

For me it's fixed by changing single-quotes to double-quotes.

I changed

gcloud compute ssh --zone us-east1-b instance-1 --command 'echo hello'

to

gcloud compute ssh --zone us-east1-b instance-1 --command "echo hello"

Upvotes: 2

dgaviola
dgaviola

Reputation: 2469

I found the issue. If you install from the Debian packages following this instructions:

https://cloud.google.com/sdk/#debubu

it will install an old version of gcloud. After installing using these instructions:

https://cloud.google.com/sdk/#nix

I got the latest version (0.9.83) and was able to execute the command without issues.

Upvotes: 4

Related Questions