leostereo has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use File::Tail; use Cwd qw(); my $path = Cwd::cwd(); $SIG{'CHLD'} = "wait_for_child_to_die"; my $community='public'; my $snmp_fver = '.1.3.6.1.4.1.2700.1.1.8.0'; my $file = File::Tail->new( name =>'/var/log/messages', interval => 1, maxinterval => 1, # resetafter=> 5, ); while (defined(my $line=$file->read)) { #print $line,"\n"; if ($line =~ /^(.*) dns02cor dhcpd: DHCPACK on ([0-9\. +]+) to ([[:xdigit:]:]+).* ([0-9\.]+)/) { unless (my $pid = fork) { die "Couldn't fork " unless defined $pid; write_register($1,$2,$3); exit; } } } sub write_register { my ($date,$client_ip,$client_imsi) = @_; $output=qx(snmpwalk -v2c -t1 -c $community $client_ip $snmp_fver 2>&1 +); chomp($output); if( $output eq "Timeout: No Response from $client_ip" ) { return; } else{ my @result=split(/:/,$output); if ($result[3]){ $fver=$result[3]; $fver=~s/ //g; $fver=~s/\n//g; }else{ exit; } } if($bsid){ system "sed -i '/$client_imsi/d' $path/leases_list.txt +"; system 'echo "'.$date.','.$client_ip.','.$client_imsi.','. $fv +er.'" >> '.$path.'/leases_list.txt'; } } sub wait_for_child_to_die { wait; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Im I forking properly ?
by flexvault (Monsignor) on Apr 14, 2016 at 21:26 UTC | |
|
Re: Im I forking properly ?
by NetWallah (Canon) on Apr 15, 2016 at 04:36 UTC | |
by leostereo (Beadle) on Apr 18, 2016 at 14:47 UTC | |
|
Re: Im I forking properly ?
by Anonymous Monk on Apr 15, 2016 at 13:40 UTC | |
by leostereo (Beadle) on Apr 18, 2016 at 14:45 UTC | |
by leostereo (Beadle) on Apr 18, 2016 at 14:50 UTC | |
by Athanasius (Archbishop) on Apr 19, 2016 at 07:00 UTC |