【发布时间】:2016-09-06 06:10:29
【问题描述】:
我在使用我的期望脚本发送长命令时遇到问题。我正在使用 telnet 访问路由器:
#! /usr/bin/expect -f
#
#
spawn telnet 192.168.0.5
expect {
"login:"
{
send "admin\r"
expect "Password:"
send "admin\r"
expect ">"
send "enable\r"
expect "Password:"
send "\r"
# My Command
expect "#"
send "terminal length 0\r"
expect "#"
send "show running-config | include ip nat pool-group\r"
}
}
expect "#"
send "exit\r"
我在php中使用exec来运行上面的脚本
<?php
exec(mybinfile , $returnvalue);
print_r($returnvalue);
当我检查输出时,似乎发送了不正确的命令。但是,它仍然有效。为什么会这样输出?
结果如下:
[14] => R1#terminal length 0
[15] => R1#show running-config | include ip nat pool-gro$ng-config | include ip nat pool-grou $ng-config | include ip nat pool-group
我尝试减少命令中的字符数,如下例所示,这很好:
show running-config | include ip nat pool-gro
如果这是我在print_r 中看到的输出,我会遇到问题吗?
【问题讨论】:
-
Will I encounter problems if that is the output I can see in print_r?不会。不会有问题,这就是 expect 的工作方式。字符串越长,越乱。 -
它是删除设备、telnet 本身以及 expect 如何从 telnet 捕获输出的组合。这与“期望如何工作”和“胡言乱语”无关。当您“手动”远程登录到该设备时,某些文本是否显示为粗体或突出显示?