diff --git a/bin/ec2-ssh b/bin/ec2-ssh index 3afd98b..f86e4bd 100755 --- a/bin/ec2-ssh +++ b/bin/ec2-ssh @@ -4,7 +4,7 @@ set -e usage() { cat< +Usage: ec2-ssh [-k KEY] [-s SECRET] [-r REGION] [-t TAG] [-p PORT] Open an ssh connection to an EC2 instance where =tag:value. The 'tag:' portion of is optional, and defaults to 'Name'. @@ -15,6 +15,7 @@ For a list of instances, run ec2-host without any paramteres -s, SECRET Amazon EC2 Secret, defaults to \$AWS_SECRET_ACCESS_KEY -r, REGION Amazon EC2 Region, defaults to us-east-1 -t, TAG Tag name for searching, defaults to 'Name' + -p, PORT Set SSH port value (default 22) EOF } @@ -23,13 +24,15 @@ test $# -eq 0 && { usage; exit; } # Process options cmd="ec2-host" -while getopts ":hk:s:r:t:" opt; do +port=22 +while getopts ":hk:s:r:t:p:" opt; do case $opt in h ) usage; exit 1;; k ) cmd="$cmd -k $OPTARG";; s ) cmd="$cmd -s $OPTARG";; r ) cmd="$cmd -r $OPTARG";; t ) cmd="$cmd -t $OPTARG";; + p ) port="$OPTARG";; \? ) usage; exit 1 esac done @@ -67,4 +70,4 @@ cmd="echo \\\". ~/.bashrc && PS1='\[\e]0;$inst: \w\\\a\]\[\\\033[01;32m\]$inst\[ if test "${@:2}"; then cmd="${@:2}" fi -test -n "$host" && echo "Connecting to $host." && exec sh -c "ssh -t $user@$host \"$cmd\"" +test -n "$host" && echo "Connecting to $host:$port." && exec sh -c "ssh -t -p $port $user@$host \"$cmd\""