执行情况如下:我是登录到一个A服务器上通过内网再登录到B服务器,A到B就是用的expect脚本,shell中嵌套了expect。但是很奇怪,我执行脚本之后发现登录了B服务器,但是回车没有回文,过一会还是在A服务器上,等于没跳过去,脚本根本没实习自动登录的功能。求求大神,给点指导。谢谢、谢谢~
# ./login.sh
spawn ssh toor4nsn@192.168.2.60
You are about to access a private system. This system is for the use
of authorized users only. All connections are logged to the extent and
by means acceptable by the local legislation. Any unauthorized access
or access attempts may be punished to the fullest extent possible
under the applicable local legislation.
Password:
Last login: Thu Feb 1 12:01:58 UTC 2018 from 192.168.2.111 on pts/0
root@fctj-0a:~ >
[root@OAM-0(RAC-1) /chenxq]
#
[root@OAM-0(RAC-1) /chenxq]
#
[root@OAM-0(RAC-1) /chenxq]
#
[root@OAM-0(RAC-1) /chenxq]
脚本内容如下:
#!/bin/sh
#Author-cxq
username="toor4nsn"
hostname=192.168.2.60
password="aaa"
/usr/bin/expect <<-EOF
spawn ssh $username@$hostname
expect {
"yes" {
send "yes\r"
expect "*assword"
send "$password\r"}
"*assword" {
send "$password\n"
}
interact
expect eof
EOF
谢谢你哈,给我提供针对性的答案。我的问题是登录之后又退出来了,这是为啥,我就是按照你给我发的要求写的。为啥还会登出呢?
只保留interact即可!
拓展:interact //交互模式,用户会停留在远程服务器上面.