我可以使用一些帮助来解析一个配置文件,其中我创建了列表,其中每个列表都有以下格式;来自配置文件(如下所示)。我试图让我的脚本读取配置文件并列出主机名之后的每个接口的详细信息。在
PE1-Loopback0-1.1.1.1 255.255.255.255
PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0
PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0
PE2-Loopback0-2.2.2.2 255.255.255.255
PE2-GigabitEthernet1.10-205.1.1.2 255.255.255.0
PE2-GigabitEthernet1.999-10.10.1.2 255.255.255.0
我的脚本如下:
^{pr2}$我的脚本输出:
PE1-Loopback0-1.1.1.1 255.255.255.255
PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0
PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0
PE1-Loopback0-2.2.2.2 255.255.255.255
PE1-GigabitEthernet1.10-205.1.1.2 255.255.255.0
PE1-GigabitEthernet1.999-10.10.1.2 255.255.255.0
我想我知道为什么我的输出是这样的。第一个for循环(forloop1)为hostname运行一个regex,然后继续执行第二个for循环(forloop2);我认为这就是我的问题所在。第一个循环继续报告PE1,第二个循环继续解析regex参数下的配置文件。我希望第二个循环在看到另一个主机名条目时结束,这样我的脚本就可以解析PE2下的接口详细信息,而不是PE1。在
结果应该如下所示:
PE1-Loopback0-1.1.1.1 255.255.255.255
PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0
PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0
PE2-Loopback0-2.2.2.2 255.255.255.255
PE2-GigabitEthernet1.10-205.1.1.2 255.255.255.0
PE2-GigabitEthernet1.999-10.10.1.2 255.255.255.0
配置文件:
hostname PE1
!
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
!
interface Tunnel999
ip unnumbered Loopback0
mpls ip
mpls label protocol ldp
tunnel mode mpls traffic-eng
tunnel destination 2.2.2.2
tunnel mpls traffic-eng autoroute announce
tunnel mpls traffic-eng path-option 10 dynamic
tunnel mpls traffic-eng path-selection metric te
tunnel mpls traffic-eng name PE1-TO-PE2
!
interface GigabitEthernet1
no ip address
negotiation auto
ip rsvp bandwidth
!
interface GigabitEthernet1.10
encapsulation dot1Q 10
ip address 205.1.1.1 255.255.255.0
mpls ip
mpls label protocol ldp
mpls traffic-eng tunnels
mpls traffic-eng administrative-weight 100
ip rsvp bandwidth 99
!
interface GigabitEthernet1.999
encapsulation dot1Q 999
ip address 10.10.1.1 255.255.255.0
!
hostname PE2
!
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
!
interface Tunnel999
ip unnumbered Loopback0
mpls ip
mpls label protocol ldp
tunnel mode mpls traffic-eng
tunnel destination 2.2.2.2
tunnel mpls traffic-eng autoroute announce
tunnel mpls traffic-eng path-option 10 dynamic
tunnel mpls traffic-eng path-selection metric te
tunnel mpls traffic-eng name PE1-TO-PE2
!
interface GigabitEthernet1
no ip address
negotiation auto
ip rsvp bandwidth
!
interface GigabitEthernet1.10
encapsulation dot1Q 10
ip address 205.1.1.2 255.255.255.0
mpls ip
mpls label protocol ldp
mpls traffic-eng tunnels
mpls traffic-eng administrative-weight 100
ip rsvp bandwidth 99
!
interface GigabitEthernet1.999
encapsulation dot1Q 999
ip address 10.10.1.2 255.255.255.0
!!!解决了的!!!
输出
^{pr2}$相关问题 更多 >
编程相关推荐