CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Perl script cannot fork more than 10 times


New User

Oct 22, 2012, 1:01 PM

Post #1 of 1 (1550 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 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.


#!/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){
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->waitfor('password: ', 15);


$ssh->waitfor('$ ', 10);

my @commresult=$ssh->exec("uptime");

print $login_output;
print @commresult;

exit 0;
else {
die "Could not Fork()\n";

waitpid($_, 0)

Please help out Thanks, nblu.




Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives