TCL script
May 28, 2010 at 12:38 am | Posted in Blogroll, TCL | 2 CommentsHere’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}
2 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Create a free website or blog at WordPress.com.
Entries and comments feeds.
[…] 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 […]
Pingback by Tclsh – Creating Scripts in IOS « Root Bridge— February 4, 2012 #
Thanks for posting I found this really useful in my study towards CCNP.
Comment by rootbridge— February 4, 2012 #