LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2010, 04:50 AM   #1
jenus
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Rep: Reputation: 0
Weird TCL Expect problem


Hi all,

I hope someone can help me out here. I have a TCL expect script that spawns a telnet session to a Nortel DMS100 to execute some commands. The strange thing is that the response in expect_out is not consistent. It sometimes contains a extra enter or newline. This results in differences in the expect out buffer. Here is a part of the script:

send "time\r"
sleep 1
expect -re ">"
set output $expect_out(buffer)
set output [split $output "\r\n"]
puts $output


This command displays the time. The correct output should be (with log_user=1):

>time
Time is 11:44:04
>

But sometimes the output is:

>timeTime is 11:45:04
>

As you can see here the \r is missing on the command that expect sends , or at least in the echo that is comming back.

I use a split command to filter out the response in the expect_out buffer, but this fails when the \r is missing. Here is a example with the debug enabled:

Wrong:
----------------------------------------------------------
send: sending "time\r" to { exp4 }

expect: does "" (spawn_id exp4) match regular expression ">"? no
timeTime is 11:47:11
>
expect: does "timeTime is 11:47:11\r\r\n>" (spawn_id exp4) match regular expression ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "timeTime is 11:47:11\r\r\n>"
{timeTime is 11:47:11} {} {} >
-----------------------------------------------------------

Good:
------------------------------------------------------------
send: sending "time\r" to { exp4 }

expect: does "" (spawn_id exp4) match regular expression ">"? no
time
Time is 11:47:59
>
expect: does "time\r\nTime is 11:47:59\r\r\n>" (spawn_id exp4) match regular expression ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "time\r\nTime is 11:47:59\r\r\n>"
time {} {Time is 11:47:59} {} {} >
--------------------------------------------------------------

I suspect it has something to do with a slow response of the switch. I tried to send the time command slow and with the send_human but the result is the same. A timeout between the send and expect also doesen't help.

Does anyone here have a clue how to further debug/fix this issue?

Thanks,

Jenus
 
Old 12-02-2010, 07:28 AM   #2
jenus
LQ Newbie
 
Registered: Dec 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Just made a tcpdump from the telnet session and it seems the DMS sometimes doesen't send the \r , wich results in the command and output on the same line.

can it be this has something to do with the telnet line/character mode? The DMS uses a IBM AIX unix machine, thats where i'm telnetting to. I tried to replicate the same issue on a cisco device but here i don't have the issue. So it seems that it has something to do with the AIX unix telnet implementation.

Last edited by jenus; 12-02-2010 at 08:02 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
expect (Tcl) question kristof_v Programming 2 01-24-2013 05:32 AM
Weird tcl/expect problem.. not able to send a string.. threeonethree Programming 0 11-28-2010 03:55 AM
TCL e EXPECT gustavolinux Programming 1 10-17-2008 09:03 AM
TCL, Expect, for Rsync - Please Help dholingw Programming 2 02-08-2004 10:27 AM
Weird ISP problem: expect (#) weppnesp Linux - Newbie 0 10-06-2002 12:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration