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 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: 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