Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea
.DS_Store
server_config
2 changes: 2 additions & 0 deletions server_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
服务器名称 22 220.181.57.217 root passphrase key ~/private_key.pem
新浪服务器 22 66.102.251.33 root sina.com
35 changes: 24 additions & 11 deletions ssh_login
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@

#默认服务器配置项
# "服务器名称 端口号 IP地址 登录用户名 登录密码/秘钥文件Key 秘钥文件地址"

CONFIGS=(
"服务器名称 22 220.181.57.217 root passphrase key ~/private_key.pem"
"新浪服务器 22 66.102.251.33 root sina.com"
)
CONFIG_FILE=~/.ssh_server_config

#读取自定义服务器配置文件(server_config)列表,合并服务器配置列表
if [ -f server_config ]; then
while read line
do
CONFIGS+=("$line")
done < server_config
if [ ! -f $CONFIG_FILE ]; then
cp server_config $CONFIG_FILE
fi

#读取自定义服务器配置文件(server_config)列表,合并服务器配置列表
while read line
do
if [ ${line:0:1} != '#' ]; then
CONFIGS+=("$line")
fi
done < $CONFIG_FILE

#服务器配置数
CONFIG_LENGTH=${#CONFIGS[*]} #配置站点个数

Expand All @@ -40,6 +44,11 @@ function ConfigList(){
done
}

# 修改配置文件
function EditConfig () {
vi $CONFIG_FILE
}

#登录菜单
function LoginMenu(){
if [ ! -n $1 ]; then
Expand Down Expand Up @@ -82,7 +91,9 @@ function AutoLogin(){
\"*assword\" {set timeout 6000; send \"${CONFIG[4]}\n\"; exp_continue ; sleep 3; }
\"*passphrase\" {set timeout 6000; send \"${CONFIG[4]}\r\n\"; exp_continue ; sleep 3; }
\"yes/no\" {send \"yes\n\"; exp_continue;}
\"Last*\" { send_user \"\n成功登录【${CONFIG[0]}】\n\";}
\"$*\" {send \"echo Login Success 成功\n\";}
\"Last\" {send \"echo Login Success 成功\n\";}
\"Welcome\" {send \"echo Login Success 成功\n\";}
}
interact
";
Expand All @@ -105,12 +116,14 @@ function AutoLogin(){

# 程序入口
if [ 1 == $# ]; then
if [ 'list' == $1 ]; then
if [ 'list' == $1 ] || [ '-l' == $1 ]; then
ConfigList
elif [ 'edit' == $1 ] || [ '-e' == $1 ]; then
EditConfig
else
AutoLogin $1
fi
else
LoginMenu
ChooseServer
fi
fi