
nblu
New User
Oct 22, 2012, 1:01 PM
Post #1 of 1
(1521 views)
|
Perl script cannot fork more than 10 times
|
Can't Post
|
|
My perl code does not allow more than 10 forks. For the following perl code, whenever I use more than 10 machines in the list of machines read in to the script, the perl script only forks 10 processes for 10 machines and for the rest it dies with error: SSHProcessError The ssh process was terminated. at serverLogin.pl 44 It dies at the line where it says $ssh->waitfor('The authenticity of host*',15);. To explain: the perl script logs in to machines specified in the file read in and issues a command on the remote machines then exits. PERL SCRIPT: #!/usr/bin/perl -w use Net::SSH::Expect; use Term::ReadKey; print "please enter filename:\n"; $filename = ReadLine; chomp $filename; print "please enter user ID:\n"; $userID = ReadLine; chomp $userID; print "please enter password:\n"; ReadMode 'noecho'; $passwordforuser = ReadLine 0; chomp $passwordforuser; ReadMode 'normal'; open READFILE,"<","$filename" or die "Could not open file listofmachines\n"; my @listofmachines = <READFILE>; foreach $machine (@listofmachines) { my $pid=fork(); if ($pid){ push(@childprocs,$pid); } elsif ( $pid == 0 ) { my $ssh = Net::SSH::Expect->new ( host => "$machine", user => "$userID", password=> "$passwordforuser", timeout => 25, raw_pty => 1, ); my $login_output = $ssh->run_ssh or die "Could not launch SSH\n"; $ssh->waitfor('The authenticity of host*',15); #print "This output for machine $machine\n"; $ssh->send("yes"); $ssh->waitfor('password: ', 15); $ssh->send("$passwordforuser"); $ssh->waitfor('$ ', 10); my @commresult=$ssh->exec("uptime"); print $login_output; print @commresult; exit 0; } else { die "Could not Fork()\n"; } } foreach(@childprocs){ waitpid($_, 0) } Please help out Thanks, nblu. |