fork and hanging



I have been searching for the problem on the net but unable to get a
good answer so I'd like to post it here for help.

I have attempted to simultaneously ssh to a number of boxes (with
openssh 3.5p1 - 3.9p1) via forking subprocesses. However, there always
seem to be a few ssh sessions got stuck and thus, my control (parent)
process cannot exit. I have searched for similar problems regarding
ssh hanging with fork, but most results indicated that the issue was
on the remote machine with an inappropriately demonized process (ie.
not redirect 3 input streams). In my scenerio, the forking doesn't
happen on remote site and the remote command is just a simple one
(uname) as demonstrated in the scripts enclosed below.

In this setting, I have an 'expect' script (spawn.exp) used to cache
the password and feed it to spawned processes (ssh.pl). I am not sure
if there is any animosity between Perl fork and ssh that I am not
aware of?

% ./spawn.exp ./ssh.pl

ssh.pl:

#!/usr/local/bin/perl -w
use strict;

my %pids;

for my $id ('01'..'05') {
my $pid = fork();
die "fork $id: $!\n" unless defined $pid;
if ($pid == 0) {
#open STDIN, '</dev/null';
#open STDOUT, '>/dev/null';
#open STDERR, '>/dev/null';
exec 'ssh', "build-$id", 'uname', '-a';
}
else {
$pids{$pid} = "build-$id";
}
}
while (%pids) {
my $pid = wait();
last if $pid == -1;
delete $pids{$pid} if exists $pids{$pid};
}

__END__


spawn.exp:

#!/usr/bin/expect --

set passwd ""
set timeout -1

eval spawn -noecho $argv
expect {
"Please try again." {
set passwd
exp_continue
}
"password:" {
if {$passwd == ""} {
stty -echo
send_user " (script) "
expect_user -re "(.*)\n"
stty echo
set passwd $expect_out(1,string)
} else {
send_user " (supplied by script) "
}
send -- "$passwd\r"
exp_continue
}
}
.



Relevant Pages

  • Expect not being able to work with a $ within a variable
    ... I have written an expect script which allows me to ssh to multiple ... loops though all the systems. ... set PASSWD ...
    (comp.lang.tcl)
  • Re: pppd pty equivilent in FBSD
    ... I let pppd manage retries & setting routes. ... >I wouldn't personally recommend vpn over ssh for anyone either, ... I'm the sole bsd user at my company, and the ppp over ssh ... >Actual bash script I call: ...
    (freebsd-net)
  • Re: [kde-linux] Sessions names
    ... ssh 192.168.2.80??? ... You can write a wrapper script that would start ssh to some ip and rename the ... konsole session dynamically. ... dcop call to konsole you need to know the pid of konsole. ...
    (KDE)
  • Re: Hacker activity?
    ... >login to a server, most as root but some are attempts to login to ... >telnet, all come from the same remote server, and all fail. ... >getting some odd cgi calls to a script on a secure ssl server. ... Make sure root cannot login to your system via ssh. ...
    (freebsd-questions)
  • Re: Ive been hacked...tips for a postmortem?
    ... > for keywords, like the email address in the `mailme' script, see if it ... www.openssh.com) That SSH1 is not to be used for anything other than ... SSH at all. ... an SSH vulnerability is to place in your startup scripts (usually rc.M, ...
    (comp.os.linux.security)