Hi there,
I am trying to create a server memory load monitor script. I was wondering if its possible to print the top command (say the top 100 processes) 'statically' to screen so that I can attach the output to the email?
thanks
I am trying to create a server memory load monitor script. I was wondering if its possible to print the top command (say the top 100 processes) 'statically' to screen so that I can attach the output to the email?
thanks
Code:
!/usr/bin/perl
$df=`w | head -n 1`;
$load=`w | head -n 1`;
$free=`free -m`;
$top=`top -n 1`; # this is what I am trying to figure out ..
$email_body="";
if ($load=~ /load average: (.)/) {
if ($1>4) { send_email(); }
}
# sending the email:
sub send_email() {
$hostname=`hostname`;
$Mailer = '/usr/sbin/sendmail -t';
open MAIL,"|$Mailer";
print MAIL <<EMAIL;
From: alerts\@domain.com
To: webmaster\@domain.com
Subject: Memory Usage Warning: $hostname
Server: $hostname $load
free -f:
$free
top:
$top
EMAIL
close MAIL;
}