【发布时间】:2013-07-03 16:59:25
【问题描述】:
我有 Ubuntu 9.10(由于测试,近期无法更改)和 expect5.45。 期望正在工作,但我(至少)有两个问题。 首先是期望似乎与字符串“密码:”不匹配。 在我的机器上,手动交互显示如下:
root@Monkey2:~# rlogin $remoteAddress -l root
root@nn.nn.nnn.nnn's password:
Linux systest-desktop 2.6.31-22-generic #70-Ubuntu SMP Wed Dec 1 23:51:13 UTC 2010 i686
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
72 packages can be updated.
70 updates are security updates.
Last login: Mon Jun 20 13:40:22 2011 from monkey2.local
root@systest-desktop:~#
脚本内容如下:
#!/usr/local/bin/expect -f ## Connect to a neighboring linux box. spawn ssh nn.nn.nnn.nnn -l root expect "password:\n" send "mypassword\n" send "$expect_out(0,string)"
脚本获取并显示请求密码但超时的行。 我试过使用“密码:”、“密码:”、“密码:\r”和密码:*”,但似乎没有一个匹配。
第二个问题是无法识别expect_out变量,运行脚本时出现以下错误(其名称为'this',只有11行!):
无法读取“expect_out(0,string)”:没有这样的变量 在执行时 "发送 "$expect_out(0,string)"" (文件“this”第 18 行)
【问题讨论】: