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)
#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}

Advertisement

One thought on “Tcl-Script Variations

Please leave a Reply

Fill in your details below or click an icon to log in:

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 )

Connecting to %s

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