From 00f07362b55183907760974f643b0af65deb1d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?changong=28=E9=BE=9A=E6=BE=84=29?= Date: Fri, 27 Apr 2018 14:17:43 +0800 Subject: [PATCH 1/2] added -l,-e option, and added config file support --- .gitignore | 1 - server_config | 2 ++ ssh_login | 31 +++++++++++++++++++++---------- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 server_config diff --git a/.gitignore b/.gitignore index 1729b92..090a1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea .DS_Store -server_config diff --git a/server_config b/server_config new file mode 100644 index 0000000..8e1f863 --- /dev/null +++ b/server_config @@ -0,0 +1,2 @@ +服务器名称 22 220.181.57.217 root passphrase key ~/private_key.pem +新浪服务器 22 66.102.251.33 root sina.com diff --git a/ssh_login b/ssh_login index 9944973..e43c6b0 100755 --- a/ssh_login +++ b/ssh_login @@ -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[*]} #配置站点个数 @@ -40,6 +44,11 @@ function ConfigList(){ done } +# 修改配置文件 +function EditConfig () { + vi $CONFIG_FILE +} + #登录菜单 function LoginMenu(){ if [ ! -n $1 ]; then @@ -105,12 +114,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 \ No newline at end of file +fi From c7205ce98023a1bb957f2f13b95355c5830fb131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?changong=28=E9=BE=9A=E6=BE=84=29?= Date: Mon, 28 Oct 2019 20:07:26 +0800 Subject: [PATCH 2/2] fix: fixed login locked --- ssh_login | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ssh_login b/ssh_login index e43c6b0..0941530 100755 --- a/ssh_login +++ b/ssh_login @@ -91,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 ";