Multithreading 无法在perl线程中打开ssh连接
我正在用perl编写一个脚本,它将能够在不同的主机上并行执行多个操作。我使用Net::OpenSSH进行ssh会话生成,因为我需要能够捕获命令的输出。当我从主线程初始化ssh连接时,EverythSign正常,但以下脚本返回以下错误: 无法建立SSH连接:无法建立主SSH连接:控制命令失败:子进程8392不存在:无子进程 有人知道如何解决这个问题吗 非常感谢Multithreading 无法在perl线程中打开ssh连接,multithreading,perl,ssh,Multithreading,Perl,Ssh,我正在用perl编写一个脚本,它将能够在不同的主机上并行执行多个操作。我使用Net::OpenSSH进行ssh会话生成,因为我需要能够捕获命令的输出。当我从主线程初始化ssh连接时,EverythSign正常,但以下脚本返回以下错误: 无法建立SSH连接:无法建立主SSH连接:控制命令失败:子进程8392不存在:无子进程 有人知道如何解决这个问题吗 非常感谢 our $threads{'1'} = { 'thread' => '0', 'ssh' => '0'
our $threads{'1'} = {
'thread' => '0',
'ssh' => '0'
};
threadsInitialization();
sub threadsInitialization{
$threads{'1'}->{'thread'} = threads->create(sub {script();});
$threads{'1'}->{'thread'}->join();
}
sub script{
print("Test action will be executed now...\n");
$threads{'1'}->{'ssh'}=sshInit(<host>,<user>,<passwd>); #<- error
#execute some actions
}
sub sshInit{
my ($host, $user, $passwd) = @_ or die "No arguments were supplied";
print("Establishing ssh connection to $host as $user...\n");
my $ssh = Net::OpenSSH->new("$host", user => "$user", passwd => "$passwd", master_opts => [-o => "StrictHostKeyChecking=no"], timeout => 600);
$ssh->error and die "Couldn't establish SSH connection: ". $ssh->error;
print("ssh connection to $host as $user established successfully.");
return $ssh;
}
our$threads{'1'}={
“线程”=>“0”,
“ssh”=>“0”
};
线程化();
亚中国化{
$threads{'1'}->{'thread'}=threads->create(sub{script();});
$threads{'1'}->{'thread'}->join();
}
子脚本{
打印(“现在将执行测试操作…\n”);
$threads{'1'}->{'ssh'}=sshInit(,);#new($host),user=>“$user”,passwd=>“$passwd”,master_opts=>[-o=>“strithhostkeychecking=no”],超时=>600);
$ssh->error and die“无法建立ssh连接:”。$ssh->error;
打印(“以$user身份成功建立到$host的ssh连接”);
返回$ssh;
}
这是第四个常见问题解答,谢谢!在原始脚本中,我有$SIG{CHLD}=“IGNORE”。这可能导致了问题。我用当地的$SIG{CHLD}代替了它;现在看来效果不错。请你把你的回答概括为回答而不是评论好吗?