user389955
user389955

Reputation: 10457

How to run local shell script on remote GCP machine via gcloud compute?

I have a script at local machine and want to run it at remote gcp server via gcloud's ssh.

I know how to do that using regular ssh command:

ssh user@remotehost "bash -s" < local_script.sh

which has been explained at https://askubuntu.com/questions/204065/how-to-run-local-shell-script-on-remote-server-via-ssh

what is I want is to use gcloud computer ssh:

gcloud beta compute ssh --zone MYZONE MYINSTANCE --project MYPROJECT ...

so far I have tried:

gcloud beta compute ssh --zone MYZONE MYINSTANCE --project MYPROJECT -- 'local_script.sh'

of course it failed, with error:

bash: local_script.sh: command not found

How can I do the similar as ssh user@remotehost "bash -s" < local_script.sh using gcloud cmd? in the worst case I will copy the file to remote machines and run there but I am not allowed to write anything at the remote machines.

Upvotes: 0

Views: 1654

Answers (1)

smemsh
smemsh

Reputation: 114

it can be invoked in the same way as standalone ssh, you need only include -- to separate gcloud options from arguments given to ssh:

gcloud compute ssh user@host -- bash -s < local_script.sh

Upvotes: 1

Related Questions