For Programmers: Free Programming Magazines  


Home > Archive > Tcl > January 2008 > expect with forking multiple foreground processes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author expect with forking multiple foreground processes
nazrat

2008-01-30, 10:42 pm

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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com