Home: Perl Programming Help: Intermediate:
Help with perl script?

New User

Nov 20, 2009, 10:39 PM

Views: 664
Help with perl script?

Hello Guys,

I am a new member and need quick help on understanding few scripts.

Let me explain you a scenerio. I am in verse to monitor a web server on Linux.All I got a script which will run on remote web Server and collect few details like:

time, Load, Load, Load, Memory used, Memory free, Cached, Swap used, Swap Free, Apache processes, Load Manager factor, Max apache, Busy

I am doing it through ssh remoteuser@<ipaddr> "perl ./script-to-monitor count_pages" | /home/john/graph/mailme.pl

Now I tested with first running it in remote server itself and its running without any issue.

Next I am too getting it the o/p in my local monitoring system which I setup in Linux. But the problem is mailme.pl script which i couldnt understand.Here is the one:


$| = 1;

last if /^\s*$/;
$subject = $_;

open( LOG, ">>$subject.log" );

$subject.='.rrd' if !/\.rrd$/;
my $filename = $subject;

print STDERR "$subject\n";

$last_reading = `rrdtool last $filename`;

while ($line = <>) {
$orig = $line;
$line =~ s/^.+?://;
print LOG $line."\n";
@data = split /:/, $line;
next if(!$data[0]);
next if($data[0]<=$last_reading);
$cmd = "rrdtool update $filename $line";
#print $cmd;
print `$cmd`;
print "$orig"

Can anyone help me in understanding what this script is doing?