Last active
August 29, 2015 14:06
-
-
Save caiyili/a94073ed842b1c96d58e to your computer and use it in GitHub Desktop.
ssh connect between two machine
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 | |
CONF=$HOME/.local/etc/goto.conf | |
EXPECT=$HOME/.local/bin/doexpect.sh | |
function goto { | |
if [[ "$1" == "-l" || "$1" == "" ]] ;then | |
__list_info | |
else | |
echo "connect to $1 ..." ; | |
_connect $1 | |
fi | |
} | |
function __list_info { | |
cat $CONF | awk -F"\t" 'BEGIN{OFS="\t"} {print $1,$2"@"$3}' | |
} | |
function __list { | |
cat $CONF | awk -F"\t" 'BEGIN{OFS="\t"}{print $1}' | |
} | |
function __go_complete { | |
local curw | |
COMPREPLY=() | |
curw=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=($(compgen -W '`__list`' -- $curw)) | |
return 0 | |
} | |
function _connect { | |
local name=$1 | |
local line=$(cat $CONF | awk -F"\t" -v name=$name '$1 == name{print $2,$3,$4}' | head -n1) | |
echo "connect $line" | |
if [[ "$line" == "" ]]; then | |
echo "$name not in conf file!" | |
else | |
$EXPECT $line | |
fi | |
} | |
complete -F __go_complete goto |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用方法:
1)在~/.bashrc或者~/.bash_profile中·source /path/to/goto.sh·
2)直接输入goto 列出可选择的登录机器
3)goto $aliasname 连接到指定的机器上