Skip to content

Instantly share code, notes, and snippets.

@caiyili
Last active August 29, 2015 14:06
Show Gist options
  • Save caiyili/a94073ed842b1c96d58e to your computer and use it in GitHub Desktop.
Save caiyili/a94073ed842b1c96d58e to your computer and use it in GitHub Desktop.
ssh connect between two machine
#!/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
@caiyili
Copy link
Author

caiyili commented Sep 19, 2014

使用方法:
1)在~/.bashrc或者~/.bash_profile中·source /path/to/goto.sh·
2)直接输入goto 列出可选择的登录机器
3)goto $aliasname 连接到指定的机器上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment