andrwj
8/1/2012 - 5:52 PM

connect remote ssh server easily.

connect remote ssh server easily.

#!/bin/bash

# if $0 looks like id@domain
#	then login as id 
# else
#	login as default user

__DEFAULT_SSH_LOGIN_UID__="root"
__self__="`basename $0`"
__tmp__="`mktemp -t uid`"

echo $__self__ | awk 'BEGIN { FS = "@" } ; { print $1 }'  > $__tmp__
__uid__="`cat $__tmp__`"

if [[ "$__uid__" == "" ]]; then
	__uid__=${__DEFAULT_SSH_LOGIN_UID__}
fi

echo $__self__ | awk 'BEGIN { FS = "@" } ; { print $2 }'  > $__tmp__
__host__="`cat $__tmp__`"

rm -f $__tmp__

ssh -l ${__uid__} ${__host__}