Created
March 14, 2013 00:01
-
-
Save migrs/5157665 to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
set -e | |
ssh='ssh' | |
ec2din="ec2-describe-instances" | |
while [ $# -gt 0 ]; do | |
case $1 in | |
-*) | |
if [ -z "$2" ]; then | |
break | |
elif [ "${2:0:1}" == "-" ]; then | |
args="$args $1" | |
shift | |
else | |
args="$args $1 $2" | |
shift 2 | |
fi | |
;; | |
*) | |
if [ -n "$1" -a -z "$name" ]; then | |
name=$1 | |
shift | |
fi | |
break | |
esac | |
done | |
if [ -n "$name" ]; then | |
if [ "$name" != "${name%\#*}" ]; then | |
num=${name#*\#} | |
name=${name%\#*} | |
fi | |
[ -z "$num" ] && num=1 | |
if [ "$name" != "${name%@*}" ]; then | |
user=${name%@*} | |
name=${name#*@} | |
fi | |
q="-F \"tag:Name=$name\"" | |
host=`$ec2din $q --hide-tags | grep ^INSTANCE | cut -f4 | paste -s | cut -f$num` | |
if [ -n "$host" ]; then | |
echo $host >&2 | |
else | |
echo ec2-ssh: Could not find ec2 instance $name [$num] >&2 | |
exit 1 | |
fi | |
fi | |
if [ -n "$user" ]; then | |
exec $ssh $args $user@$host $@ | |
else | |
exec $ssh $args $host $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment