我正在开发一个expect脚本,该脚本连接到交换机,然后显示接口的配置。然后我分析这个输出来检查某些事情。我想要存储我正在检查的一件事情的输出,我正试图通过$expect_out(缓冲区)进行搜索来完成这一任务,尽管我很难找到如何做到这一点。
我该怎么做呢?
脚本如下所示(去掉不必要的内容):
send "show running-config interface $intf\r"
log_user 0
expect "#"
if {[string match "*service-policy input Access-Port*" $expect_out(buffer)]} {
set servicepolicy "yes"
} else {
set servicepolicy "no"
}
if {[string match "*mls qos trust dscp*" $expect_out(buffer)]} {
set mlsqos "yes"
} else {
set mlsqos "no"
}
if {[string matc "*Description*" $expect_out(buffer)]} {
EXTRACT DESCRIPTION STRING FROM $expect_out(buffer)
}$expect_out(缓冲区)的输出通常如下所示:
Current configuration : 559 bytes
!
interface GigabitEthernet1/0/17
description blablabla
switchport mode access
switchport voice vlan xxxxx
no logging event link-status
authentication event fail retry 0 action authorize vlan xxxxx
authentication event no-response action authorize vlan xxxxx
authentication host-mode multi-domain
authentication port-control auto
authentication violation restrict
mab
no snmp trap link-status
dot1x pae authenticator
dot1x timeout tx-period 5
dot1x timeout supp-timeout 10
no mdix auto
spanning-tree portfast
service-policy input Access-Port
end“从$expect_out(缓冲器)提取描述字符串”行是我试图找出的部分。我知道如何拆分行来获取描述,但我只是不知道如何从缓冲区变量中提取行本身。
发布于 2015-08-29 12:03:57
使用regexp命令和-line选项:
% regexp -line {^\s*description (.*)$} $expect(buffer) -> desc
1
% puts $desc
blablabla我想描述不是多行的。
另外,如果你只需要一个布尔值,
set servicepolicy [string match "*service-policy input Access-Port*" $expect_out(buffer)]或者,做这个
set servicepolicy [expr {[string match "*service-policy input Access-Port*" $expect_out(buffer)] ? "yes" : "no"}]https://stackoverflow.com/questions/32282412
复制相似问题