小编Mik*_*ris的帖子

期望不识别$ expect_out(缓冲区)或$ expect_out(0,字符串)

我有Ubuntu 9.10(由于测试不能在不久的将来改变它)和expect5.45.期待是有效的,但我(至少)有两个问题.第一个是期望似乎与字符串"password:"不匹配.在我的机器上,手动交互显示如下:

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:~# 
Run Code Online (Sandbox Code Playgroud)

脚本的内容如下:

#!/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)"
Run Code Online (Sandbox Code Playgroud)

该脚本获取并显示请求密码的行但超时.我尝试使用"密码:","密码:","密码:\ r"和密码:*"但似乎没有匹配.


第二个问题是expect_out变量无法识别,当我运行脚本(其名称为'this'且只有11行!)时,我收到以下错误:

无法读取"expect_out(0,string)":执行"send"时没有这样的变量$ expect_out(0,string)""(文件"this"第18行)

ssh ubuntu expect

5
推荐指数
1
解决办法
5292
查看次数

标签 统计

expect ×1

ssh ×1

ubuntu ×1