Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/checking-an-attribute.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
checking an attribute

Posted by priyadharshini (priyadharshini), 8 May 2008
Hi,
I wrote an Expect script to send commands to a router and capture the router's routing table. I need to check the value of some attributes of a particular route entry in the routing table. in some routers the routing table are in table format like the following,
Codes: R - RIP, Rc - RIP connected, Rs - RIP static, Ra - RIP aggregated,^M^M
      Rcx - RIP connect suppressed, Rsx - RIP static suppressed,^M^M
      K - Kernel, C - Connected, S - Static, O - OSPF, I - IS-IS, B - BGP^M^M
^M^M
  Network                     Next Hop                  If     Met Tag  Time^M^M
Rc 3:1:1:1::/64                ::                        ethernet0/2   1   0 ^M^M
Rc 5:1:1:1::/64                ::                        ethernet0/2   1   0 ^M^M

in some others it looks like,

1.0.0.0/8    auto-summary^M
1.1.1.1/32^M
   [1] via 170.1.1.5, 00:00:05, FastEthernet0/0^M
2.0.0.0/8    auto-summary^M
2.2.2.2/32    directly connected, Loopback2^M
170.1.0.0/16    auto-summary^M
170.1.1.0/24    directly connected, FastEthernet0/0^M
180.1.0.0/16    auto-summary^M
180.1.1.0/24^M
   [1] via 170.1.1.5, 00:00:05, FastEthernet0/0^M

can you please help me to do this?

Thank you,

Posted by admin (Graham Ellis), 8 May 2008
Yes, I probably can help but I need to know a little more.  I understand that you already have the strings from the router saved into a varaible, but it may be one of two formats and you need to identify which it is and extract some infomation from it - is that correct?

Taking the examples you have given, can you tell me which the information you wantg to extract is in each case?

Thanks

Posted by priyadharshini (priyadharshini), 8 May 2008
Thank you for your timely reply. Your understanding is right.
In different places 'm checking different attribute values. for example at on place i need to check whether the metric of a route entry is equal to some number, in some other places i 'll be checking whether a particular interface with its ip address exists in the routeing table or not. some places 'm checking the time attribute of a route entry.

Thank you,

Posted by admin (Graham Ellis), 9 May 2008
But not being an expert in those particular reports and the background behind them, I remain unsure as to how I can help / advise.  Please do quote an example of

* This is the string I may get
* This is what I want to extract from it
* These are the parts that are invarient to help you recognise it

Actually, that's a pretty good general principle statment for specifying a regular expression!

Posted by priyadharshini (priyadharshini), 9 May 2008
1. This is the content of the output buffer.

^M
^M                                            ^MSR4134/configure/interface/ethernet (0/2)# exit^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# interface loopback 1^M
configuring existing loopback interface^M
1=======>^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ip address 1.1.1.1 255.255.255.255^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# show ip int br^M
Interface                  Type              IP-Address/Mask    Status^M
ethernet0/1                ETHERNET (802.3)  175.4.2.90/24      Down^M
ethernet0/2                ETHERNET (802.3)  180.1.1.5/24       Up^M
ethernet0/4                ETHERNET (802.3)  170.1.1.5/24       Up^M
100                        S/W LOOPBACK      100.100.100.100/32 Up^M
1                          S/W LOOPBACK      1.1.1.1/32         Up^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# ^M
^M                                        ^MSR4134/configure/interface/loopback 1# exit^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# end^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134# configure terminal^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# router rip^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# version 2^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# network 170.1.1.0/24^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# network 1.1.1.1/32^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# network 180.1.1.0/24^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# show ip rip data^M
^M^M
Codes: R - RIP, Rc - RIP connected, Rs - RIP static, K - Kernel,^M^M
      C - Connected, S - Static, O - OSPF, I - IS-IS, B - BGP^M^M
^M^M
  Network            Next Hop         Metric From            If     Time^M^M
Rc 1.1.1.1/32                               1                 1     ^M^M
Rc 170.1.1.0/24                             1                 ethernet0/4^M^M
Rc 180.1.1.0/24                             1                 ethernet0/2^M^M
^M^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# ^M
^M                              ^MSR4134/configure/router/rip# exit^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# ^M
^M                   ^MSR4134/configure# end^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134# ^M
^M         ^MSR4134#

Here 'm expecting
Rc 170.1.1.0/24                             1                 ethernet0/4^M^M
Rc 180.1.1.0/24                             1                 ethernet0/2^M^M


The routing table follows the "show ip rip database". The 1st column in the routing table is a code that specifies the route category.  I need to check whether the code is Rc for a network (used with the network cammand in router mode), the metric value is 1 and the interface is the one specified in the interface command(global terminal mode).

At the neighbor routers routing table the routing entry 'll have a different metric value and the next hop 'll be the ip address that was specified with ip address command(interface mode).

NEIGHBOR-1's ROUTING TABLE
1.0.0.0/8    auto-summary^M
1.1.1.1/32^M
   [1] via 170.1.1.5, 00:00:05, FastEthernet0/0^M
2.0.0.0/8    auto-summary^M
2.2.2.2/32    directly connected, Loopback2^M
170.1.0.0/16    auto-summary^M
170.1.1.0/24    directly connected, FastEthernet0/0^M
180.1.0.0/16    auto-summary^M
180.1.1.0/24^M
   [1] via 170.1.1.5, 00:00:05, FastEthernet0/0^M

here 'm expecting
170.1.1.0/24    directly connected, FastEthernet0/0^M


NEIGHBOR-2's ROUTING TABLE
  Network            Next Hop         Metric From            If     Time^M^M
R  1.1.1.1/32         180.1.1.5             2 180.1.1.5       ethernet3/8 02:55^M^M
R  2.0.0.0/8          180.1.1.5             3 180.1.1.5       ethernet3/8 02:55^M^M
Rc 3.3.3.3/32                               1                 3     ^M^M
R  170.1.1.0/24       180.1.1.5             2 180.1.1.5       ethernet3/8 02:55^M^M
Rc 180.1.1.0/24                             1                 ethernet3/8^M^M

Here 'm expecting
R  170.1.1.0/24       180.1.1.5             2 180.1.1.5       ethernet3/8 02:55^M^M

Thank you,




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho