gcloud compute远程执行命令 [英] gcloud compute execute command remotely
本文介绍了gcloud compute远程执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,如果要在VM上执行某些操作,则可以通过以下方式复制文件:
Currently, if I want to execute something on a VM, I copy files over like this:
gcloud compute --project <project_id> copy-files --zone <zone_name> /home/roman/source/dir roman@<vm_name>:/some/path
然后我需要像这样手动SSH:
Then I need to SSH into it manually like this:
gcloud compute --project <project_id> ssh --zone <zone_name> <vm_name>
然后去运行一些命令:
cd /some/path
python example.py
如何将第2步和第3步结合在一起并远程执行命令?
How do I combine step 2 and 3 together and execute a command remotely?
注意:我想使用gcloud或python api.我不想使用Fabric之类的第三方软件包.
Note: I want to use gcloud or the python api. I don't want to use 3rd party packages like Fabric.
推荐答案
尝试:
$ gcloud compute ssh --zone ZONE INSTANCE -- 'cd /tmp && python some.py'
来自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
这篇关于gcloud compute远程执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文