【问题标题】:How to catch a count ports on Cisco Nexus Devices using tcl/expect?如何使用 tcl/expect 在 Cisco Nexus 设备上捕获计数端口?
【发布时间】:2023-03-14 02:04:01
【问题描述】:

我编写了一个脚本来捕获 Cisco Nexus 设备上的连接端口计数,如下所示:

指挥思科:

example01#sh interface status | i connected | exclude Po | exclude Lo|count
13
example01#

脚本部分:

send "sh interface status \| i connected \| exclude Po \| exclude Lo \| count\r"
expect -re {([0-9]+)}
set COUNT "$expect_out(0,string)"
puts "$COUNT\r"

问题是设备的主机名也有数字,比如 01。当我保存输出时,我看到的只是“01”,而不是我期望的正确输出(这种情况下是 13)。

【问题讨论】:

    标签: tcl expect cisco


    【解决方案1】:

    我这样做了:

    send "sh interface status \| i connected \| exclude Po \| exclude Lo \| count\r"
    expect -re {([0-9]+)\r\n}
    set COUNT "$expect_out(0,string)"
    puts "$COUNT\r"
    

    现在,输出是正确的,因为我用\r\n 换行了。

    【讨论】:

    • 您还可以在该正则表达式的开头放置一个^{^([0-9]+)\r\n} — 以进一步限制可能性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2011-11-22
    • 2012-10-27
    • 2015-11-21
    相关资源
    最近更新 更多