diff --git a/README.md b/README.md index 0b0c0f1..88bb4ef 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# update by fei33423 + 新增登录后 cd 到指定的路径. 配置文件中最后一列 + 1:192.168.88.128:22:root:toor:虚拟机web服务器:/root/ + # so This is a SSH login tool diff --git a/password.lst b/password.lst index 32e26c0..3e02f22 100755 --- a/password.lst +++ b/password.lst @@ -1,3 +1,3 @@ -1:192.168.88.128:22:root:toor:虚拟机web服务器 +1:192.168.88.128:22:root:toor:虚拟机web服务器:/root/ 2:192.168.88.130:22:ca0gu0:toor:虚拟机mysql数据库服务器 103:192.168.88.4:22:root:sellercube:本地开发服务器 diff --git a/so.sh b/so.sh index d3b6dbb..8158bc5 100755 --- a/so.sh +++ b/so.sh @@ -49,7 +49,7 @@ while [ True ];do port=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $3}}' $pw) username=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $4}}' $pw) passwd=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $5}}' $pw) - + dir=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $7}}' $pw) case $number in [0-9]|[0-9][0-9]|[0-9][0-9][0-9]) echo $passwd | grep -q ".pem$" @@ -58,7 +58,7 @@ while [ True ];do ssh -i $direc/keys/$passwd $username@$ipaddr -p $port echo "ssh -i $direc/$passwd $username@$ipaddr -p $port" else - expect -f $direc/ssh_login.exp $ipaddr $username $passwd $port + expect -f $direc/ssh_login.exp $ipaddr $username $passwd $port $dir fi ;; "q"|"quit") diff --git a/ssh_login.exp b/ssh_login.exp index 13aaa26..a10ea99 100755 --- a/ssh_login.exp +++ b/ssh_login.exp @@ -3,11 +3,15 @@ set TARGET [lindex $argv 0] set USER [lindex $argv 1] set PASSWD [lindex $argv 2] set PORT [lindex $argv 3] +set DIR [lindex $argv 4] set timeout 10 -spawn ssh $USER@$TARGET -p $PORT +spawn ssh $USER@$TARGET -p $PORT +#'cd /root/' expect { "*yes/no" {send "yes\r"; exp_continue} "*password:" {send "$PASSWD\r"} } +send "cd $DIR\r" +send "pwd\r" interact