-
-
Save sebastianvera/567fd1b0b2d9c9928081da9ed758524c to your computer and use it in GitHub Desktop.
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 | |
# | |
# Simple script to login via ssh to google instances | |
# | |
# Usage: gssh [--list] INSTANCE_NAME | |
GCLOUDCMD=$( which gcloud ) | |
if [ -z "$GCLOUDCMD" ]; then | |
echo "gcloud not found" | |
else | |
echo "found gcloud bin: $GCLOUDCMD" | |
fi | |
if [ -z "$1" ]; then | |
echo "Missing parameters" | |
echo "Usage: gssh [--list] INSTANCE_NAME" | |
fi | |
if [ "$1" == "--list" ] || [ "$1" == "-l" ]; then | |
echo "getting instances list" | |
gcloud compute instances list | |
else | |
echo "looking for instance named $1" | |
REGION=` gcloud compute instances list | grep ^$1\ | awk {'print $2'} ` | |
if [ -z $REGION ]; then | |
echo "instance not found" | |
else | |
gcloud compute ssh $1 --zone=$REGION | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment