我知道可以像这样使用ssh (在文件中)远程执行命令;
#!/bin/sh
ssh ${USER}@${SERVER_IP} <<EOF
cd ${PROJECT_PATH}
git pull
exit
EOF我的问题是:对gcloud计算ssh也可以这样做吗?我是说;
gcloud compute ssh vm-internal --zone us-central1-c --tunnel-through-iap << EOF
...
...
EOFPS:实例是私有的,没有外部IP,因此使用iap。
发布于 2020-09-11 22:38:07
只要您可以将ssh放到实例上,就应该能够:
gcloud compute ssh .... --command="bash -s" <<EOF
echo "Hello Freddie"
ls -l
EOF您可以测试这一点(多亏了使用Cloud的gcloud一致性):
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
stackoverflowhttps://stackoverflow.com/questions/63854277
复制相似问题