cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
9152
Views
0
Helpful
5
Replies

TCL in IOS - how to insert a carriage return

gespahl
Level 1
Level 1

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

5 Replies 5

yjdabear
VIP Alumni
VIP Alumni

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

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

You want:

typeahead "y" ; exec "clear line 37"

mushamim
Cisco Employee
Cisco Employee

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

cscbrannent
Level 1
Level 1

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

Review Cisco Networking for a $25 gift card