perl - Parallel::ForkManager 给出 - 子进程 STDIN 不是真正的系统错误
问题描述
我有一个脚本,如果服务器(@hosts
)存储在数组中并在这些主机上执行某些命令,它会执行 ssh 编号。
...
use Net::OpenSSH;
use Parallel::ForkManager;
#these hosts are the IP addresses
my @hosts = ("host1", "host2", "host3", "host4", "host5");
my $ssh;
my $command = "perl -e "print \"Hello..\"";
my $pm = Parallel::ForkManager->new(5);
LOOP:
foreach my $n (@hosts) {
my $pid = $pm->start and next LOOP;
#doing ssh to the host and running the command
#lets say here I am executing simple Perl command
$ssh = Connect($n, "user", "passwd");
$ssh->capture($command);
$pm->finish;
}
$pm->wait_all_children;
undef $ssh;
sub Connect {
my ( $host, $user, $passwd ) = @_;
my $ssh = Net::OpenSSH->new($host, user=>$user, password=>$passwd);
$ssh->error and die "Couldn't establish SSH connection: " . $ssh->error;
return $ssh;
}
...
当我执行这个脚本时,我遇到了错误,这对我来说就像噩梦一样。
child process STDIN is not a real system file handle at (eval 2) line 145
我不知道为什么会发生此错误。有人可以帮我解决这个问题。
我错过了什么$pm->finish
还是需要添加$pm->run_on_finish(..)
?
解决方案
推荐阅读
- javascript - 如何使用 jquery + flask 请求更新 html 而无需重新加载网页?
- javascript - 在 React 组件中将字符串化对象作为道具传递是否比普通 JavaScript 对象更好?
- logging - NDepend 可以检测 C# 中字符串插值的位置吗?
- makefile - 更改 makefile 以处理“make all”命令
- node.js - 您能否验证我的 cloudbuild.yaml 文件?
- python - 为 CPLEX 安装选择特定的 python 版本 (Windows 10)
- apache-kafka - 无法在 Windows 机器上设置 Apache Zookeeper 和 Kafka
- database - 长时间运行的查询会导致应用程序性能下降吗
- amazon-web-services - 为什么当我尝试使用 SSH(在我的电脑中使用浏览器和 ssh)连接 ec2 时会超时?
- reactjs - 在 React 中,如何在单元测试中实例化一个没有构造函数的类?