Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

TCL Script Needed!!!

Hi, everyone that like that kind of stuff. I am ready to become an expert of TCL scripts, especially when back in college i used to do lots of C++, VB etc. This was 8, 9 years ago.. Anyway, i am just getting started but i need some help I need a script for my PE routers, and ideas would be great. here is what i need

I would like to have a script that pings all the ips within a VRF on my PE routers. here is what i am trying to do. i would like to ping each of the my MPLS customers from each of the PE routers, with following results, if i get 9 out of 10 pings, i get PASSED message and if not i get FAILED, this script works when i have one foreach and one if, but i do not want to have multiple files for each VRF, i would like to integrate everything in one. The only thing that sucks is to enter ip addresses i want to ping manually. is there a way for TCL sript to execute arp in each vrf, and ping every host in the ARP table on PE router and /32 routing entry per VRF (loopbacks). this would be ideal. Any help approciated.

foreach addressgrate {

167.10.10.5

65.214.241.18

65.214.241.22

65.214.241.30

}

foreach address {

10.8.2.1

10.8.2.2

10.8.2.7

10.8.0.45

10.3.1.1

10.3.2.1

10.3.0.26

10.3.0.3

172.16.64.1

172.16.68.1

} {

if { [regexp "(!!!!!!!!!)" [exec "ping vrf CUST1 $address rep 10" ]] } {

puts "$address   ****** PASSED CUST1 *******"

} else { puts "$address ****** FAILED CUST1******" }

}

if { [regexp "(!!!!!!!!!)" [exec "ping vrf CUST2 $addressgrate rep 10" ]] } {

puts "$address   ****** PASSED CUST2*******"

} else { puts "$address ****** FAILED CUST2******" }

}

CCIE 18676
1 REPLY
Cisco Employee

Re: TCL Script Needed!!!

Something like this should work:

foreach vrf [list "CUST1" "CUST2"] {

    set ips [list]

    set output [exec "show arp vrf $vrf | inc Internet"]

    foreach line [split $output "\n"] {

        lappend ips [lindex $line 1]

    }

    set output [exec "show ip route vrf $vrf | inc /32"]

    foreach line [split $output "\n"] {

        if { [regexp {([\d\./]+)/32 \[} $line -> ip] } {

            lappend ips $ip

        }

    }

    foreach ip $ips {

        set output [exec "ping vrf $vrf $ip rep 10"]

        if { [regexp {!!!!!!!!!} $output] } {

            puts "$ip   ****** PASSED $vrf *******"

        } else {

            puts "$ip ****** FAILED $vrf ******"

        }

    }

}

1064
Views
0
Helpful
1
Replies