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

Traceroute TCL Script on Cisco c4500 [Cisco IOS XE]

Netmart
Level 1
Level 1

Hello,

I was wondering, how to create, save, and run a TCL script on Cisco c4500 [Cisco IOS XE] performing a traceroute and saving the output to txt file.

 

Thanks,

5 Replies 5

Francesco Molino
VIP Alumni
VIP Alumni

Hi

 

Sorry if there're some mispelling error.

Just wrote something quick over ipad.

Can you test this script?


set fileoutput [open "flash:tracerouteresult.txt" w]
foreach address {8.8.8.8 1.1.1.1} {
set output [exec "traceroute $address source g0/0"]
puts $fileoutput $output
}
close $fileoutput

Replace g0/0 by your source interface from where the traceroute should be initiated.

Put this script into a tcl file called traceroute.tcl (example of name, you can call it whatever you want), then put this file into the flash and from the device you can run it using the command:

tclsh flash:traceroute.tcl

 


Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Thank you Francesco.

 

I tried to apply this script, but there still seems some adjustments necessary:

 

RTR(tcl)#set fileoutput [open "bootflash:tracerouteresult.txt" w]

file21

RTR(tcl)#foreach address {

+>8.8.8.8

+>1.1.1.1} {set output [exec "traceroute $address source vlan 125"]

+>puts $fileoutput $output

+>}

                    ^

% Invalid input detected at '^' marker.

 

Could you please take a look.

 

Thanks,

As I said previously, you can create a text file with the tcl extension and upload it into your device.
If you want to create it locally using tclsh command line, you would need to put the code into the following:

puts [open "flash:traceroute.tcl: w+] {
code-sent-previously
}

Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question

Thank you for providing me with this info.

 

However, there seems to bit more into it including a bug when executing the traceroute command in certain IOS XE versions; see link below for more details:

 

https://community.cisco.com/t5/network-management/tcl-and-traceroute/td-p/1778334

 

Have you ever tried your posted suggestions?

Yes i used it but not on latest devices. Since Cisco provides a guest shell (Linux CentOS container) on IOS-XE, i only use this machine with Python scripts for this kind of scripts.

I don't have any 4500 right now to test this tcl. Give me few days to test it in another device and I'll come back with some results.

Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: