пример скрипта:
#!/usr/bin/perl
use Net::Rsh;
use RRDs;
use DBI;
use strict;
my $dbuser = 'root';
my $dbpass= '';
my $db = 'mon';
my $rrdpath = '/usr/home/ro/perl/monitoring/rrd/';
my $dbh = DBI->connect("DBI:mysql
atabase=mon;host=localhost",'root','') || die;
my $a=Net::Rsh->new();
my $luser = 'ro';
my $ruser = 'ro';
my $time = time();
my $q = 'SELECT u.id, s.ip, u.cmd, u.loop, u.lastupdate FROM unit u INNER JOIN server s ON s.id = u.serverid';
my $sth = $dbh->prepare($q);
$sth->execute();
while (my $str = $sth->fetchrow_hashref())
{
if (fork() == 0)
{
if ($str->{lastupdate} + $str->{loop} > time)
{
exit;
}
my $dbc = DBI->connect("DBI:mysql
atabase=$db;host=localhost",$dbuser,$dbpass) || die;
my $t = '';
my @c;
eval
{
@c = $a->rsh($str->{ip},$luser,$ruser,$str->{cmd});
};
if ($@)
{
$t = $@;
}
else
{
if ($#c > 0)
{
for (my $i = 0; $i <= $#c; $i++)
{
$t .= $c[$i];
}
$t .= "\\n";
}
elsif ($#c == 0)
{
$t = $c[0];
}
}
$t =~ s/\\n/\\ /g;
$t =~ s/\\0//g;
$t =~ s/^\\ {1,}//g;
$t =~ s/\\ {1,}$//g;
print $str->{ip}.' \\''.$str->{cmd}."' result '$t'\\n";
RRDs::update $rrdpath.$str->{id}.'.rrd', $time.':'.$t;
my $er = RRDs::error;
if ($er)
{
$er =~ s/\\'/\\\\\\'/g;
}
$q = 'UPDATE unit SET lastupdate = '.$time.', lastresult =\\''.$t.'\\', updateresult = \\''.(($er)?$er:'OK').'\\' WHERE id = '.$str->{id};
$dbc->do($q);
open (LOG, '>>/var/log/rrd.log');
print LOG $q."\\n";
close LOG;
}
}