Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Expect script hangs after interact call

46 views
Skip to first unread message

rhsmith52

unread,
Jul 3, 2007, 7:22:32 PM7/3/07
to
TIA, I'm having a problem with what I thought would be a very simple expect script. I call
the following script with the name of a connection file. Each line in this file represents a
send and expect string, one line each, for the utmost simplicity. As we have to hop thru
any number of nodes to reach a target, I wanted to give this to my co-workers so that I
could quit writing a specific one each time it is needed.

This scripts reads 2 lines at a time in a while loop and sends the send and expect strings.
Works great up to the end of file. Then returns control to the user and everything is fine ...
for a couple of minutes or commands and then it hangs, consistently, every time. I have
no idea what the problem may be.

I've only written basic scripts up to now, this being the most, or so I thought. Obviously,
I'm doing something fundamentally wrong.

Any help would be greatly appreciated.

Regards

#!/usr/local/bin/expect
#

proc user_snd { msg } {
set cdate [ exec date ]
set datestr [ format "%-19.19s" $cdate ]
send_user "$datestr $msg\n"
}

proc send_exp { sendstr expectstr } {
global gsid logging
if { $logging == 1 } {
user_snd "Sending '$sendstr', expecting '$expectstr'";
}
send "$sendstr\r"
sleep .1
expect {
timeout {
user_snd "Timed out waiting for '$expectstr'";
exit
}
$expectstr
}
return 1
}

set timeout 30
set gsid 0

stty -echo

set Fname [ lindex $argv 0 ]
set logging [ lindex $argv 1 ]

global logging
log_user 0
user_snd "Processing input file $Fname"

spawn telnet
set file [ open $Fname ]
while {[gets $file sendstr] != -1} {
gets $file expstr
send_exp $sendstr $expstr
}
close $file
user_snd "File processing completed - Press ENTER to continue "

interact


Bezoar

unread,
Jul 12, 2007, 10:56:03 AM7/12/07
to
Don't have a whole lot of help at the moment since you have not said
anything about what you have done so far to debug the situation or
what OS's you are running on and logging into.
I notice that you have not put the terminal back into a sane state
prior to your interact call. I have not checked the book but it might
be a requirement that the terminal be in a sane state before interact
will work. What debugging have you done to this point? Does the
hangup occur only on multple hops or one telnet session? Can you
login in to the destination machine and ensure that your session still
exists when the hangup occurs? Do the remote machines have an auto
logout mechanism. In unix if the TIME_OUT environment variable is set
to anything other than 0 it will log you within the number of seconds
noted in $TIME_OUT ( bash and sh shells). Are you setting the tty in
multiple hops to -echo also ?Have you tried setting log_user and
exp_internal at the interact stage to see your responses. Also you
can monitor your spawned session using truss or strace to see if any
signals are being recieved and what I/O is being done. The return
value from spawn is the pid ( process id) puts that out then in
another window run : ( this is Linux) strace -p <pid> as you interact
you should see writes and reads that the system gets see how it
matches with what expect gets. Do the same on the remote system's
session till you find the cause.
Also you exec date instead of using the tcl 'clock' command an exec
involves a fork and exec and is not transferable between OS's. I
believe your call can be replaced by
set datestr [ clock -format [clock seconds ] ]

Carl

0 new messages