-
-
Save scjody/29ad8c003a1bd5ff15e10b54926eb110 to your computer and use it in GitHub Desktop.
"gcloud compute ssh" wrapper to figure out the zone automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOST="$1" | |
if [[ $HOST = *"@"* ]] ; then | |
USER=$(echo $HOST | cut -d'@' -f1) | |
HOST=$(echo $HOST | cut -d'@' -f2) | |
fi | |
gcloud config list | grep 'Your active' | |
ZONE=$(gcloud compute instances list |grep -E "^$HOST[[:space:]]" | awk '{print $2}') | |
echo zone: $ZONE | |
gcloud compute ssh --zone=$ZONE "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this in your path and you'll be able to connect to an instance without figuring out its zone in advance:
gssh jody-imageserver-test
If you use multiple configurations (
gcloud config
) to deal with more than one project, you'll need to be sure you've selected the correct configuration. This wrapper makes that easier.