Tcl-Script Variations

Ok, so we all know that a TCL can be cool.  But are you using the easiest why to do the all well-known ping-script.
Let me show you 3 ways to do the same thing, and then the really cool lazy way.

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}


One thought on “Tcl-Script Variations

Please leave a Reply

Fill in your details below or click an icon to log in: 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.