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 {
61.88.88.88
2.2.2.2
123.123.123.123
33.33.33.33
google.com
www.news.com.au
} {
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

Reference:

http://blog.ru.co.za/2009/03/28/tcl-script-variations/#more-684 

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)
#tclsh
puts [open "flash:ping-script.tcl" w+] {
foreach IP {
150.1.1.1
204.12.1.254
} { puts [ exec "ping $IP re 2" ] }
}
(tcl)#tclquit

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
#tclsh
proc ping-script {} {
foreach IP {
150.1.1.1
204.12.1.254
} { puts [ exec "ping $IP re 2" ] }
}
(tcl)#ping-script

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.
#tclsh
foreach IP {
150.1.1.1
204.12.1.254
} { 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)
#tclsh
foreach IP {
150.1.1.1
204.12.1.254
} {ping $IP re 2}

Advertisements

2 Comments »

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: