Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/simultaneous-expect-problem.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
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))
simultaneous expect problem

Posted by topher (topher), 15 February 2008
Hi,
I inhereited an expect script.
(we are playing games with host keys changing.
we want to make sure there is no prompting for our scripts, by running this 1st) It seems to work fine.
But when the parent script fires off 2 of them at once, the first one always returns a "timeout".

I turned on user_log and I can see the authentication successful messages. I did a ps while it was running and I see the expect script had one defunct process.
So, it looks like the ssh fired up, worked and exited.
But the expect script doesn't seem to see that.

I was running expect 5.34. I upgraded to 5.42.
But that didn't help.

Any help would be greatly appreciated.

I'm assuming it's something in the script. Here it is:

#!/usr/bin/expect --
#
# Module: dtha_test_ssh
#
log_user 0
set IP [ lindex $argv 0 ]
set CMD "cd"

if { [ catch { spawn ssh $IP $CMD } result ] } {
       puts $result
       exit 80
}

set timeout 60

expect {

       ;# can recover from this one
       -re "continue connecting" {
               send "yes\r"
               exp_continue
       }

       -re "change the host key on disk" {
               send "yes\r"
               exp_continue
       }

       -re "Please select one" {
               send "save\r"
               exp_continue
       }

       -re "select how you want to proceed." {
               send "save\r"
               exp_continue
       }

       -re "assword:" {
               exit 81
       }

       timeout {
               exit 82
       }

       eof {
               # close is implicit after eof, wait for ret vector
               set retv [ wait ]
               set retc [ lindex $retv 3 ]
               exit $retc
       }
}

# should never get here, but just in case
catch { close; wait -nowait } result

exit 85



Posted by admin (Graham Ellis), 16 February 2008
Is the parent script also an expect script, firing off the other two with a source command?   If so, you'll have a conflict in your spawn_id ... and results rather like those your describe.

Solution.  

1. Save your spawn_id just after your spawn command into a separate variable (and a different one for each of the two threads.

2. Use the -i option on your expect commands (giving the saved variable name) so that it waits for the specified process rather than the default one.



Posted by topher (topher), 18 February 2008
Hi,

No the parent scripts are perl scripts.
Here's the run down.

My fo script has a list of applications.
It forks for each one. The child processes call the start script.

The start script calls the expect script.
The first start gets back the RC of 82 from the expect script.



In playing around with this script I found if I bump the timeout up to 120, it seems to not fail.
The symptoms are pretty much the same.
2 calls to this script happen at once. They both fire up a ssh call. Both ssh processes go defunct quickly.
The 2nd expect script finishes up. The 1st expect script hangs around for about 90 seconds, then finishes.

Any idea what's causing the delay?





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.

© 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