Cisco Support Community
Community Member

[TCL - MDF] - Remove routes


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:


<Item ContinuePrompt="true">


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



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




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 DHCP 4"





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.



Cisco Employee

Re: [TCL - MDF] - Remove routes

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

Community Member

[TCL - MDF] - Remove routes


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



Cisco Employee

[TCL - MDF] - Remove routes

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

Community Member

[TCL - MDF] - Remove routes


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

Thanks a lot !


Community Member

[TCL - MDF] - Remove routes


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.


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"


  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

CreatePlease to create content