I receive an error while running this script. It goes an gets a list of
IP addresses that are on the network, then collects SNMP data from them.
There are 8 modems available.
10.100.254.255
10.100.254.252
10.100.255.252
10.100.253.255
10.100.255.254
10.100.255.253
10.100.255.251
10.100.254.254
10.100.254.253
When the script is run I see this output:
#./fork-control-test.pl
10.100.254.255
10.100.254.252
10.100.255.252
10.100.253.255
10.100.255.254
10.100.255.253
10.100.255.251
10.100.254.254
10.100.254.253
0.0.0.0
#
00:08:0E:E5:C6:AC
00:E0:6F:21:6F:34
00:E0:6F:38:54:06
Can't locate object method "writer. via package "IO::Pipe::End" at
./fork-control-test.pl line 92.
00:E0:6F:14:AD:A2
Can't locate object method "writer" via package "IO::Pipe::End" at
./fork-control-test.pl line 92.
Error Received: Can't locate object method "writer" via package
"IO::Pipe::End" at ./fork-control-test.pl line 91, <GEN0> line 1.
Line 91 of fork-control-test is
> $pipe->writer;
If the child process is something simple like print $data, it works great.
As soon as I put something in that requires some processing, filehandles, or network
traffic, I get these errors.
Does anyone see issues? What does the error actually mean?
-Mike
The entire script is below.
use strict;
use Proc::Fork;
use IO::Pipe;
use Net::SNMP;
use SNMP;
my $num_children = 4; # How many children we'll create
my @children; # Store connections to them
$SIG{CHLD} = 'IGNORE'; # Don't worry about reaping zombies
# Spawn off some children
for my $num (1..$num_children)
{
# Create a pipe for parent-child communication
my $pipe = new IO::Pipe;
# Child simply echoes data it receives, until EOF
child
{
$pipe->reader;
my $data;
while ($data = <$pipe>)
{
chomp $data;
my $com='notshown';
my (%VALUES,@tmp,@macparts,$SESSION);
$SESSION = new SNMP::Session( DestHost => $data,
Community => $com,
Version => 2,
Timeout => 1000000,
Retries => 3,
UseSprintValue => 1) ||
die("Can't connect to modem $data");
$VALUES{'ip_address'} = $data;
$VALUES{'sysDescr'} =
$SESSION->get(".1.3.6.1.2.1.1.1.0");
if(!$VALUES{'sysDescr'}) { return; }
exit -11 if (! $VALUES{'sysDescr'});
$VALUES{'mac_address'} =
$SESSION->get(".1.3.6.1.2.1.17.1.1.0");
$VALUES{'level_up'} =
$SESSION->get(".1.3.6.1.2.1.10.127.1.2.2.1.3.2");
$VALUES{'level_down'} =
$SESSION->get(".1.3.6.1.2.1.10.127.1.1.1.1.6.3");
$VALUES{'sn_ratio'} =
$SESSION->get(".1.3.6.1.2.1.10.127.1.1.4.1.5.3");
$VALUES{'sw_ver'} =
$SESSION->get(".1.3.6.1.2.1.69.1.3.5.0");
$VALUES{'config_file'} =
$SESSION->get(".1.3.6.1.2.1.69.1.4.5.0");
$VALUES{'firmware_ver'} =
$SESSION->get(".1.3.6.1.2.1.69.1.3.2.0");
$VALUES{'date'} = `date +%Y-%m-%d\\ %H:%M:%S`;
chomp $VALUES{'date'};
@macparts=split(/\"/, $VALUES{'mac_address'});
$VALUES{'mac_address'} = $macparts[1];
chomp $VALUES{'mac_address'};
$VALUES{'mac_address'} =~ s/\ /:/g;
$VALUES{'mac_address'} =~ s/:$//;
my @cf=split(/\"/, $VALUES{'config_file'});
chomp($cf[1]);
$VALUES{'config_file'} = $cf[1];
my @fw=split(/\"/, $VALUES{'sw_ver'});
$VALUES{'sw_ver'} = $fw[1];
if (! $VALUES{'sn_ratio'}) {
$VALUES{'sn_ratio'} = 0;
}
if (! $VALUES{'firmware_ver'}) {
$VALUES{'firmware_ver'} = 'Undefined';
}
# Sanitize some vars.
foreach my $l ('level_up', 'level_down', 'sn_ratio') {
if ($VALUES{$l} !~ m/^[0-9\.\-]+$/){
@tmp=split(/\ /, $VALUES{$l});
$VALUES{$l}=$tmp[1];
}
}
open(MODEMDATA, ">modemdata/$VALUES{'ip_address'}.txt");
print MODEMDATA "$VALUES{'mac_address'},";
print STDERR $VALUES{'mac_address'};
print MODEMDATA "$VALUES{'ip_address'},";
print MODEMDATA "$VALUES{'level_up'},";
print MODEMDATA "$VALUES{'level_down'},";
print MODEMDATA "$VALUES{'sn_ratio'},";
print MODEMDATA "$VALUES{'date'},";
print MODEMDATA "$VALUES{'config_file'},";
print MODEMDATA "$VALUES{'firmware_ver'},";
print MODEMDATA "$VALUES{'sysDescr'},";
print MODEMDATA "$VALUES{'sw_ver'}\n";
close(MODEMDATA);
}
exit;
};
# Parent here
$pipe->writer;
push @children, $pipe;
}
my($res_ip,@cmip,$key,%res_ip,$ip,%VALUES,@tmp,@macparts,$SESSION);
my $oid_ip=".1.3.6.1.2.1.10.127.1.3.3.1.3";
my ($session,$error_line) = Net::SNMP->session(
-hostname => '192.168.200.1',
-version => 2,
-community => 'notshown'
);
if (!defined($res_ip=$session->get_table($oid_ip))) {
printf(" %s\n", $session->error);
$error_line=$session->error;
$session->close;
next;
}
my $ipc=0;
foreach $key (sort keys %$res_ip) {
$cmip[$ipc]=$$res_ip{$key};
$ipc++;
}
$cmtstime=time();
# Send some data to the kids
foreach $ip (@cmip){
print "$ip\n";
if($ip ne '0.0.0.0'){
# pick a child at random
my $num = int rand $num_children;
my $child = $children[$num];
print $child "$ip\n";
}
}
exit;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>