h1

TCL’in Orphaned Telnet Sessions

November 27, 2008

In a previous post, I showed how to deal with hung/orphaned telnet sessions. And although that works, I find it just to annoying to enter the same command 10 times over, apart from wasting time.

So instead I wrote a really simple Tcl script yesterday, to accomplish the same. I say simple, because yesterday I didn’t really take the time to optimize the amount of lines in the scripts, which could easily be shortened to about 10 lines. Make no mistake, I’m not a code-monkey.

The Cisco IOS Scripting with Tcl feature provides the ability to run Tool Command Language (Tcl) version 8.3.4 commands from the Cisco IOS command-line interface (CLI). TCL is pronounced ‘tickle’. More info in Cisco Land.

So just to recap, same predicament as before where telnet session are hung/orphaned. Example:

shline.

We can create the TCL script manually every time, using TCLSH, but we not getting around the “being lazy” part. So a better way is to create the TCL script in flash, and execute the file from there when needed.

To create the script in flash, I called it “clear-line”, you need to enter into TCLSH mode. This will change your prompt, indicating you have entered TCLSH mode

Router# tclsh
Router(tcl)#

Next, specify the file to create, and where to store it:

Router(tcl)# puts [open "flash:clear-line" w+] {

Then  the really simple script. The first line is merely a comment, for neatness purposes. The Second line executes the needed command.

puts "Clearing line 2"
puts [ exec "clear line 2" ]
puts "Clearing line 3"
puts [ exec "clear line 3" ]
puts "Clearing line 4"
puts [ exec "clear line 4" ]
puts "Clearing line 5"
puts [ exec "clear line 5" ]
puts "Clearing line 6"
puts [ exec "clear line 6" ]
puts "Clearing line 7"
puts [ exec "clear line 7" ]
puts "Clearing line 8"
puts [ exec "clear line 8" ]
puts "Clearing line 9"
puts [ exec "clear line 9" ]
puts "Clearing line 10"
puts [ exec "clear line 10" ]
puts "Clearing line 11"
puts [ exec "clear line 11" ]
puts "Clearing line 12"
puts [ exec "clear line 12" ]
puts "Clearing line 13"
puts [ exec "clear line 13" ]
puts "Clearing line 14"
puts [ exec "clear line 14" ]
puts "Clearing line 15"
puts [ exec "clear line 15" ]
puts "Clearing line 16"
puts [ exec "clear line 16" ]
puts "Clearing line 17"
puts [ exec "clear line 17" ]
}

Confirm that the file was created in flash:

dir-tcl

Then the easy part, whenever you need to execute the script, from privilege mode issue the command “tclsh {script name}“, if the file is stored in flash, or if the file happen to be on a TFTP server: tclsh tftp://{ip}/{scriptname}

clear-line-tcl

And laziness becomes happiness. I do believe that lazy people are smart people that would find smarter ways to do more work in the shortest time.

Advertisements

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 )

Google+ photo

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

Connecting to %s