cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1986
Views
0
Helpful
5
Replies

[TCL - MDF] - Remove routes

Vivien FRANCOIS
Level 1
Level 1

Hi,

I am working on a TCL script embedded in a MDF. That MDF is reached when a specific user logs into the router through a telnet connection (username <user> autocommand emm mdf <mdf>). The goal of that TCL script is to remove every static routes set up into the routers and add a new one when the user will press on an option in the MDF file: what I am currently using works but only at the first script execution after router's boot:

[OUTPUT_OMITTED]

<Item ContinuePrompt="true">

<ItemTitle>

<Constant String="Change route for DHCP" />

</ItemTitle>

<HelpString>

<Constant String="This will change the default route for the DHCP connection"/>

</HelpString>

<EmbeddedTCL>

<TCLCommand>

set currentRoutes [exec {show run | i ip route}]

foreach rtToRemove [ regexp -all -line -inline {^ip route \[0-9\]*\.\[0-9\]*\.\[0-9\]*\.\[0-9\]* \[0-9\]*\.\[0-9\]*\.\[0-9\]*\.\[0-9\]*.*} $currentRoutes ] {

  puts "Removing route: $rtToRemove"

  ios_config "no $rtToRemove"

}

unset currentRoutes

ios_config "ip route 0.0.0.0 0.0.0.0 DHCP 4"

</TCLCommand>

</EmbeddedTCL>

</Item>

[OUTPUT_OMITTED]

At the first execution after the boot everything works fine, exec line is executed (and not displayed) and iterations in the foreach statement are performed, Though if I re-execute that option without rebooting the router the show run | i ip route is displayed in the console and routes are not removed: script seems to stop after the exec {show run | i ip route}.

Any help will be greatly appreciated.

THanks,

Vivien

5 Replies 5

Joe Clarke
Cisco Employee
Cisco Employee

What version of IOS is this?  This sounds like CSCtg89622.

Hi,

I forgot to mention: IOS used is c880data-universalk9-mz.151-2.T1.bin

Thanks.

Vivien

Yes, this is the bug I mentioned.  If you upgrade to 15.1(3)T or higher, you should be good.

Hi,

Indeed, I upgraded the IOS and it is now correctly working.

Thanks a lot !

Vivien

edwardleepto
Level 1
Level 1

Vivien,

We had the same issue. This is from CiscoTAC. Thanks for posting this 2 years ago. It was a good basis to get a script that would work.

-Eddie

FIRST, we need to run the IOS upgrade to 15.1(4)M6 and THEN, run the following EEM Applet:

conf t

event  manager applet remove-duplicate-routes authorization bypass  event tag  none none  event tag timer timer cron cron-entry "@reboot"

trigger

  correlate event none or event timer

action 001   cli command "enable"

action 002   cli command "show run | inc ^ip route"

action 003   regexp "^ip route" "$_cli_result"

action 004   set cli_output "$_cli_result"

action 005   if $_regexp_result eq 0

action 006    cli command "config t"

action 007    cli command "no event manager applet remove-duplicate-routes"

action 008    cli command "end"

action 009    cli command "write mem"

action 010    exit 0

action 011   end

action 012   cli command "config t"

action 013   foreach line "$cli_output" "\n"

action 014    string trim "$line"

action 015    regexp "^ip route" "$_string_result"

action 016    if $_regexp_result eq 1

action 017     cli command "no $_string_result"

action 018    end

action 019   end

action 020   cli command "end"

action 021   cli command "write mem"

action 022   syslog msg "Removed static routes; reloading..."

action 023   reload