2016-01-26 80 views
0

我有一些问题,我的剧本,我想期待减号后预计发送命令show |比较成junos路由器。expect脚本(期望的Junos路由器显示减号|比较)

需要有人帮助我..

脚本

expect "#" 
send "show | compare\r" 

set total_error_minus 0 
expect -- "-" 
incr total_error_minus 

示例结果

[edit]<br> 
[email protected]_lab# show | compare<br> 
[edit interfaces em0]<br> 
- description B;<br> 
+ description C;<br> 
[edit interfaces em0 unit 1]<br> 
- description A;<br> 
+ description D;<br> 

[edit]<br> 
[email protected]_lab# <br> 

如何检测和计数减演出结束后标志|使用expect脚本比较命令?

+0

不要u需要发送'enter'关键?它不需要成为'send'show | compare \ r“'吗? – Dinesh

+0

噢,我想我错过了把“\ r”,谢谢dinesh – IjanQlate

回答

0

使用标志--指定任何期权类的参数。

expect -- "-" 
+0

谢谢Dinesh,绝对是我想要的。但如果显示|比较结果如下:[编辑] pijan @ junos_lab#show |比较[edit interfaces em0] - 描述B; +说明C; [edit interfaces em0 unit 1] - description A; +说明D;我怎样才能减去预期的脚本? – IjanQlate

+0

在原文中更新此信息。无法正确读取代码。 – Dinesh

+0

Dinesh,完成请求 – IjanQlate

0

你需要你的期望语句进入一个循环:

set total_error_minus 0 
send "show | compare\r" 
expect { 
    -- "-" {incr total_error_minus; exp_continue} 
    "[email protected]_lab# " 
} 
# continue with script ... 
+0

嗨,我已经试过这段代码,但问题仍然无法解决此问题。预计减号不起作用 – IjanQlate

+0

删除后工作;增量total_error_minus和下面的脚本..期待{ - “ - ” {增量total_error_minus exp_continue}“电信@ junos_lab#”},感谢格伦·杰克曼..不错 – IjanQlate

+1

@SparK,该建议实际上编辑引入了一个语法错误。我回滚了。 –