You are right- it is far easier.
#!/usr/bin/perl -w strict use strict; use DBI; use Parallel::ForkManager; my $dbh = DBI->connect('DBI:mysql:noc', 'root', '') or die "Couldn't o +pen database: $DBI::errstr; stopped"; my $fm = new Parallel::ForkManager(10); while (1) { my $sth = $dbh->prepare("select assetid,ip,snmpname from assets") or d +ie "Couldn't prepare statement: $DBI::errstr; stopped"; $sth->execute() or die "Couldnt execute statement: $DBI::errsrt; stopp +ed"; my @ret; while ( my ($aid, $aip, $asnmp) = $sth->fetchrow_array() ) { $fm->start and next; ping_remote($aip,$aid,$asnmp); $fm->finish; } $fm->wait_all_children; sleep(5); print "repeating\n"; } sub ping_remote { my $ip = shift; my $aid = shift; my $snmpname = shift; my @ret = undef; my @p = split(/(,)/,`ping -c 1 $ip | grep "0% loss"`); if ($p[4] eq " 0% loss") { my $a=`/etc/poller/snmptraffic.php "$ip" "$snmpname"`; my $u=`/etc/poller/snmpuptime.php "$ip" "$snmpname"`; my $f=`/etc/poller/snmpfirmware.php "$ip" "$snmpname"`; @ret = ($a,$u,$f); } if (@ret) { print "$ip\n"; my $sth2 = $dbh->prepare("insert into history set assetid='$aid', +trafficload='$ret[1]'") or die "Couldn't prepare statement: $DBI::err +str; stopped"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt; +stopped"; $sth2 = $dbh->prepare("update assets set firmware='$ret[2]', uptim +e='$ret[1]', status='u', trafficload='$ret[0]' where assetid='$aid'") + or die "Couldn't prepare statement: $DBI::errstr; stopped"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt; +stopped"; } else { print "down - $ip\n"; my $sth2 = $dbh->prepare("update assets set status='d' where asset +id='$aid'") or die "Couldn't prepare statement: $DBI::errstr; stopped +"; $sth2->execute() or die "Couldnt execute statement: $DBI::errsrt; +stopped"; } }

THANKS!

In reply to Re: Re: Re: Forking Issues by satanklawz
in thread Forking Issues by satanklawz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.