Skip to content

Instantly share code, notes, and snippets.

@sundy-li
Created March 29, 2017 01:34
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 sundy-li/4661d6fca076eceb4ed94da4b7bc5b04 to your computer and use it in GitHub Desktop.
Save sundy-li/4661d6fca076eceb4ed94da4b7bc5b04 to your computer and use it in GitHub Desktop.
gossh
#!/bin/bash
# __________
# /''T''|[___|___]
# Sundyli
# [---T--L-OlllllllO-]
# ooOO2016-08-25 11:47ooOO
# ()_)"""()_)/"**")_) 什么时候才能有辆悍马呢?
# _| _ _ / '| /~~ _ _ _ _ .| _ _ _ _
# _|</(_)(_)(_).|.| (|/(_|| | |(_|||.(_(_)| | |
# / __ _|
# __________________gosshd_______________________________
GO=$1
TO=$2
SERVERS=$(cat <<EOF
chuxing@10.0.0.10:22
chuxing@10.0.0.11:22
dianxin@admin:22
ubuntu@prod1:22
ubuntu@test1:22
sundy@mine:22
EOF)
function getConnection() {
for serv in $SERVERS
do
if [ "x`echo $serv | grep "10.0.0"`" != "x" ];then
hostname="`echo $serv | sed -En 's/.*\@10\.0\.0\.([^\:]*)\:.*/\1/p'`"
elif [ "x`echo $serv | grep "prod"`" != "x" ];then
hostname="prod`echo $serv | sed -En 's/.*\@prod([^\:]*)\:.*/\1/p'`"
elif [ "x`echo $serv | grep "test"`" != "x" ];then
hostname="test`echo $serv | sed -En 's/.*\@test([^\:]*)\:.*/\1/p'`"
elif [ "x`echo $serv | grep "$1"`" != "x" ];then
hostname=$1
fi
#statements
if [ "$1" == "$hostname" ]
then
echo $serv
break
fi
done
}
if [ $# == 0 ]
then
echo -e "Usage: $0 jump dest\n"
exit
elif [ $# == 1 ]
then
g=`getConnection $GO`
else
g=`getConnection $GO`
1 #!/bin/bash
t=`getConnection $TO`
fi
if [ "x$g" == "x" ]
then
echo -e "Not Found Connection."
exit
fi
ss=${g##*@}
s_user=${g%*@*}
s_host=${ss%*:*}
s_port=${ss##*:}
if [ "x$t" != "x" ]
then
cc=${t##*@}
c_user=${t%*@*}
c_host=${cc%*:*}
c_port=${cc##*:}
echo "Connecting to $s_user@$s_host:$s_port cross $c_user@$c_host:$c_port ..."
echo -ne "\033]0;$c_user@$c_host:$c_port\007"
ssh -o StrictHostKeyChecking=no -tt -p $s_port $s_user@$s_host "ssh -o StrictHostKeyChecking=no -p $c_port $c_user@$c_host"
else
echo "Connecting to $s_user@$s_host:$s_port ..."
echo -ne "\033]0;$s_user@$s_host:$s_port\007"
ssh -o StrictHostKeyChecking=no -p $s_port $s_user@$s_host
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment