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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho