通过中转IP来执行命令,并在执行命令后自动退出。实现和SSH命令相同效果,适用某些时候需要中转节点使用的情况。
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
my_ssh() {
throughBy="192.168.1.168"
if [ -z "$1" ]; then
echo "Usage: connect <hostname>"
return 1
fi
local my_user my_ip
if [[ $1 == *@* ]]; then
my_user="${1%%@*}"
my_ip="${1#*@}"
else
my_user="root"
my_ip="$1"
fi
curCmd="ip a"
if [ ! -z "$2" ]; then
curCmd=$2
fi
if [ "$my_ip" == "$throughBy" ]; then
echo "Need to connect through $throughBy"
ssh -tt $throughBy "ssh $my_user@$my_ip '$curCmd'; exit"
else
ssh -tt $my_user@$my_ip "$curCmd; exit"
fi
}