I'm trying to connect to a GCP instance, which changes its public IP every time it's restarted. To get the IP dynamically I use this gcloud
command:
gcloud compute instances describe <vm-name> --zone europe-west --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
Then I have this ssh config
file:
Host MyHost
ProxyCommand ~/.ssh/vm-connect
which points to a script vm-connect
with the following contents
#!/bin/bash
get_host() {
gcloud compute instances describe <vm-name> --zone europe-west1-b --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
}
ssh minikf@$(get_host)
If I only run the script it connects to the VM successfully. But if I run ssh MyHost
it gives me:
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: SSH-2.0-OpenSSH_8.2p1: command not found