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..0941530 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 @@ -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 "; @@ -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 \ No newline at end of file +fi