TCL in IOS - how to insert a carriage return

Unanswered Question
Aug 6th, 2010

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

I have this problem too.
0 votes
  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Loading.
gespahl Tue, 08/10/2010 - 06:21

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

mushamim Thu, 01/29/2015 - 18:45

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 Wed, 12/16/2015 - 08:13

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

Actions

This Discussion

Related Content