So I am having an issue with the array @cpuAll losing its value after $pm->finish.. This is just SSHing to a bunch of servers and bringing back some stats which works fine. But the array won't print after the last loop is done. I don't want to write everything to files because I get a 90% performance increase from just loading it into the array.
my @cpuAll = ();
my @memAll = ();
$pm->run_on_finish(sub{
my ($pid,$exit_code,$ident,$exit_signal,$core_dump,$data)=@_;
push(@data,$data);
});
for(@servers)
{
next if $_ =~ "10.1.4.52";
next if $_ =~ "10.1.4.106";
my $pid = $pm->start and next;
chomp;
my @output_cpu = `/usr/bin/ssh $_ \"/root/scripts/punkbuster.cpu|sed 's/ (//g'|sed 's/)//g'|sed s'/ //g'\"`;
for(@output_cpu)
{
chomp;
my ($server,$username,$cpu,$process)=(split /:/, $_)[0,1,2,3];
# push(@cpuAll,"$server\,$username\,$cpu\,$process\,$date\,$time\n");
}
$pm->finish(0, [$server,$username,$cpu,$process]);
}
print $_ for @data;
print "OK\n";
$pm->wait_all_children;