Skip to content

Instantly share code, notes, and snippets.

@sebastianvera
Created December 5, 2019 16:28
Show Gist options
  • Save sebastianvera/567fd1b0b2d9c9928081da9ed758524c to your computer and use it in GitHub Desktop.
Save sebastianvera/567fd1b0b2d9c9928081da9ed758524c to your computer and use it in GitHub Desktop.
#!/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