gcloud compute execute command remotely

前端 未结 3 529
一生所求
一生所求 2021-02-01 16:21

Currently, if I want to execute something on a VM, I copy files over like this:

gcloud compute --project  copy-files --zone  /         


        
相关标签:
3条回答
  • 2021-02-01 17:08

    A gcloud update that landed a week ago blocked passing ssh commands after '--' and effectively forces use of --command option for this. In this case use:

    gcloud compute ssh --zone ZONE INSTANCE --command 'cd /tmp && python some.py'.

    0 讨论(0)
  • 2021-02-01 17:09

    Try:

    $ gcloud compute ssh --zone ZONE INSTANCE -- 'cd /tmp && python some.py'
    

    From gcloud compute ssh --help:

     [-- IMPLEMENTATION-ARGS ...]
        Flags and positionals passed to the underlying ssh implementation.
    
        The '--' argument must be specified between gcloud specific args on the
        left and IMPLEMENTATION-ARGS on the right. Example:
    
            $ gcloud compute ssh example-instance --zone us-central1-a -- -vvv \
                -L 80:%INSTANCE%:80
    
    0 讨论(0)
  • 2021-02-01 17:20

    Did it with a bit of a tangent; using the normal ssh client instead of gcloud compute:

    ssh -i ~/.ssh/google_compute_engine roman@<vm_IP> 'python /some/path/example.py'
    

    The gcloud ssh key is located at ~/.ssh/google_compute_engine, which it uses. It also requires the external IP address of the instance instead of its name.

    0 讨论(0)
提交回复
热议问题