expect with forking multiple foreground processes



Hi all,

I have read up the Expect manpage and a other examples for fork. The
manpage warns that always fork first before spawning processes, but I
can't quite figure out how to come up with a solution for my problem
as described.
I'd like to simultaneously ssh to several remote machines to run a
command via ssh, wait for the output from each of the machine to come
back to my terminal and then exit. I would like to enter the password
only once and it should be cached and fed to the ssh sessions. How can
i get around this with expect/fork? Thanks much.

I am totally a newbie to tcl/expect (just read the manpage) so bare
with me the following miserable attempt:

#!/usr/bin/expect --

send_user "Please enter password: "
expect_user -re "(.*)\n"
for {set i 1} {i < 10} {incr i} {
if {[fork] == 0} {
set host "host$i"
eval spawn -noecho ssh $host 'uname -a'
expect "password:"
send "$expect_out(1,string)\r"
exit
}
}

My questions are:
1 - how can i wait for the forked subprocesses in the parent (control)
process?
2 - if the entered password is incorrect, how can a subprocess inform
the control process so it can re-prompt the user to enter again?

Thanks much.
.



Relevant Pages

  • Re: ssh forwarding environment variables
    ... no mention of it in the sshd_config manpage ... ... the remote system being machine B, the one running sshd, the one into ... > environment in the remote session, but I don't think that's how it ... every ssh connection into it ... ...
    (Debian-User)
  • Re: ssh time to see if remote server is up
    ... Does SSH have an option to fix ... Take a look at the ssh_configmanpage, ... connection being timed out if there was no transfer. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: SSH timeout settings
    ... >> Hey all, I think this is an easy one masquerading as a ... >> of SSH? ... never implemented and should be removed from the manpage. ...
    (FreeBSD-Security)
  • Re: ssh forwarding environment variables
    ... when i connect via ssh. ... >> relevant on the sshd manpage, so i don't think i need to do anything ... >> to the sshd config on machine B. ...
    (Debian-User)
  • Re: SSH attack
    ... Alvin Oga wrote: ... I meant sending the email alert as described in the manpage. ... Still it seems better to start ssh from inetd for security reasons. ...
    (Debian-User)