如何解决有没有一种方法可以使用gcloud compute ssh实用程序远程执行命令
我知道可以像这样使用ssh(在文件中)远程执行命令;
#!/bin/sh
ssh ${USER}@${SERVER_IP} <<EOF
cd ${PROJECT_PATH}
git pull
exit
EOF
我的问题是这样的:是否可以对gcloud compute ssh进行相同的处理?我的意思是;
gcloud compute ssh vm-internal --zone us-central1-c --tunnel-through-iap << EOF
...
...
EOF
PS:该实例是私有的,没有外部IP,因此使用了IAP
解决方法
只要您可以SSH到实例,您就应该能够:
gcloud compute ssh .... --command="bash -s" <<EOF
echo "Hello Freddie"
ls -l
EOF
您可以对此进行测试(由于使用gcloud
使用Cloud Shell的一致性):
gcloud alpha cloud-shell ssh --command="bash -s" <<EOF
echo "Hello Freddie"
ls
EOF
注意,您可能不需要
-s
,但我认为它是首选
收益:
Automatic authentication with GCP CLI tools in Cloud Shell is disabled. To enable,please rerun command with `--authorize-session` flag.
Hello Freddie
Projects
README-cloudshell.txt -> /google/devshell/README-cloudshell.txt
stackoverflow
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。