Skip to content

Instantly share code, notes, and snippets.

@mdumrauf
Last active September 10, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdumrauf/e8f9a10671a2b201e43a to your computer and use it in GitHub Desktop.
Save mdumrauf/e8f9a10671a2b201e43a to your computer and use it in GitHub Desktop.
Utility script for connecting to EC2 instances
#/bin/sh
INSTANCE=$1
if [ -z $INSTANCE ]; then
printf 'Usage: connect [instance]\n'
echo '[instance] : nginx | production | staging | mongo | what'
exit 1;
fi
if [ $INSTANCE != 'what' ]; then printf "Connecting to $INSTANCE\n"; fi
USER="ec2-user"
case $INSTANCE in
'nginx' ) IP=xx.x.x.xxx
;;
'production' ) IP=xx.x.x.xxx
;;
'staging' ) IP=xx.x.x.xxx && USER="ubuntu"
;;
'mongo' ) IP=xx.x.x.xxx
;;
'what' ) printf "nginx: xx.x.x.xxx\nproduction: xx.x.x.xxx\nstaging: xx.x.x.xxx\nmongo: xx.x.x.xxx\n" && exit 1;
;;
* ) echo "Instance unknown." && exit 1;
;;
esac
ssh -i ~/.ssh/key.pem "$USER@$IP"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment