私の perl コードでは、10 個を超えるフォークが許可されていません。次の perl コードでは、スクリプトに読み込まれたマシンのリストで 10 台を超えるマシンを使用すると、perl スクリプトは 10 台のマシンに対して 10 個のプロセスのみをフォークし、残りのプロセスはエラーで終了します。
SSHProcessError ssh プロセスが終了しました。serverLogin.pl 44 で $ssh->waitfor('ホストの信頼性*',15); と書かれている行で停止します。
パールスクリプト:
#!/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)
}
助けてください。ありがとう、nblu。