08-06-2010 11:16 AM
Greetings,
I have a very simple TCL script which clears the lines on a terminal server:
puts [open "flash:clear2" w+] {
puts "Clearing line 33"
puts [exec "clear line 33"]
puts "Clearing line 34"
puts [exec "clear line 34"]
.
. (etc.)
.
puts "Clearing line 46"
puts [exec "clear line 46"]
}
It works fine except that I have to press enter for each line. The router's responds to the "clear line" command with a " [confirm] " and waits for the enter key to be hit. I'd like to automate this and was looking for a way to respond to the " [confirm] " within the script. I thought maybe a "catch" would work but can't seem to find a link that explains how to accomplish this. Anyone know how to do this?
Thanks in advance!
George
08-06-2010 11:47 AM
typeahead "y" (or "\r"); "typeahead" reportedly only started working correctly since 12.4(15)T.
See this for reference:
http://wiki.nil.com/Insert_responses_to_command_prompts_in_Tclsh
08-10-2010 06:21 AM
No, that doesn't seem to do it although now I see the "[confirm] " and "[OK]" after I hit the enter key. I tried adding a second typeahead as well but no luck. Thanks all the same though.
George
08-13-2010 11:11 PM
You want:
typeahead "y" ; exec "clear line 37"
01-29-2015 06:45 PM
I hacked a way to make carriage return in tclsh work. You will need the following two lines after your command line needing a carriage return (and sometimes a set before the command as well):
r
typeahead "\r"
So, for instance, to do a repeated tclsh copy tftp command that requires CR, I use in tclsh script:
...
r
typeahead "\r"
copy tftp://192.168.1.1/largefile flash:largefile
r
typeahead "\r"
...
This works fine even in a loop.
The line with r will causes "No open connections" message on CLI of no known consequences. The typeahead text is saved in the buffer and entered as user-typed input on the command line after the tclsh script command completes.
Arif
12-16-2015 08:13 AM
I googled the carriage return issue, and we're trying to do the same thing.
This is working for me, on a 3725 with 12.4(25):
tclsh
for {set i 33} {$i < 49} {incr i} {
typeahead "\r";clear line $i}
tclquit
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide