Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

Expect script terminating too early

Posted by mnmitch (mnmitch), 23 August 2006
Hi, I'm relatively new to Expect (but not to shell programming) and would appreciate any help in debugging a problem I'm having. The problem is intermittent; it seems to work about 60% of the time, so I'm having a tough time tracking root cause down.

At the heart of it, it seems the expect script is terminating prior to receiving all of the output from a command. Here is the expect script redacted (the expect script is being called from a shell script and its output being redirected to a single file):

Code:
match_max 60000

send_user "Logging onto intermediate box\n"
spawn telnet IP.of.intermediate.box
expect "login:"
sleep 2
send "username \n"
expect "Password:"
sleep 3
send "pass \n"
expect "#"
sleep 2
expect eof

send_user "Logging onto final destination\n"
send "telnet box.IP \n"
sleep 5
expect "Enter User Name"
send "username \n"
sleep 1
expect "Enter Password"
sleep 1
send "password \n"
sleep 5
expect eof

expect ">"
expect *
send "command_1 \n"
expect eof

expect ">"
expect *
send "command_2 \n"
expect eof

expect ">"
expect *
send "command_3 \n"
expect eof

expect ">"
sleep 60
send_user "Logging out\n"
send "logout \n"
expect "prompt "
exit


Each of the commands (1, 2, and 3) results in nearly 20,000 lines of output.

Here's what's occuring when the script isn't working:
1. Command 3's output is truncated
2. Commands 2 and 3 look like they're being sent before the expected ">";  in the output file they appear in the midst of the command output

I've tried issuing "sleep" commands in place of the "expect eof" to no avail. I appreciate any help; if there's another thread I've missed that's addressed this, please let me know.

Thanks in advance.

Posted by admin (Graham Ellis), 23 August 2006
As a first step, can I ask how long each of the intermeiate commands takes to run?   It sounds as if they're quite big / long - in which case they may be timing out (the default is 10 seconds).

Try adding
set timeout 60
before the first long command that you run to extend the time it waits (if it fails to detect the sequence you're expecting) to a minute .... of course, use any other figure if that would be more appropriate.  

Posted by mnmitch (mnmitch), 23 August 2006
I'll give it a shot. Thanks.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho