TCL script

May 28, 2010 at 12:38 am | Posted in Blogroll, TCL | 2 Comments

Here’s my fav:

puts [open "flash:ping-script" w+] {
puts ""
show clock
puts " -- Start pinging ..."
puts ""
foreach i {
} {
if {[regexp "!" [exec "ping $i rep 3 time 1"]]} {puts "$i OK"} else {puts "$i ***unreachable***"}}
show clock
puts " -- Pings stopped."
puts ""
(tcl)# quit

Then to execute the file from enabled mode:
#tclsh ping-script


First method is kinda cool, since you creating an executable file in flash that is there, to be used whenever.
(the w+ means to write/overwrite, or if you want to append the file use a+ instead)
puts [open "flash:ping-script.tcl" w+] {
foreach IP {
} { puts [ exec "ping $IP re 2" ] }

Then to execute the file from global configuration mode:
#tclsh ping-script.tcl

Second method is pretty pointless unless you writing a beeg script and actually using ‘process’ for what it is meant. Problem here is once you exit tcl-shell, the info is gone.
To execute while in tclsh just type the name
proc ping-script {} {
foreach IP {
} { puts [ exec "ping $IP re 2" ] }

Third method is the most common one I have seen guys use. And its not bad, but still to much syntax to remember off-hand.
This will execute the ping command once <RETURN> is pressed at the last line.
foreach IP {
} { puts [ exec "ping $IP re 2" ] }

Best method, is a almost always the shortest one. Again execution will auto follow once the script is complete.
(oh and ‘IP’ is just a arbitrary name I used, not a tcl value)
foreach IP {
} {ping $IP re 2}



RSS feed for comments on this post. TrackBack URI

  1. […] If you are looking to create scripts which you can save for future use check out this post over at Cisco Notepad Like this:LikeBe the first to like this post. Leave a […]

  2. Thanks for posting I found this really useful in my study towards CCNP.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at
Entries and comments feeds.

%d bloggers like this: