shell脚本expect自动登录后,怎么又自动退出了

执行情况如下:我是登录到一个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

追问

谢谢你哈,给我提供针对性的答案。我的问题是登录之后又退出来了,这是为啥,我就是按照你给我发的要求写的。为啥还会登出呢?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2021-08-26
去掉最后两行 expect eof 和 EOF
只保留interact即可!

拓展:interact //交互模式,用户会停留在远程服务器上面.

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网