Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print a static top view

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
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 :)


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;
}
 
Hoe about something like:
[tt]
ps -Al | sort -nrk 10 | head - 100
[/tt]
 
Sorry, that should have been:
[tt]
ps -Al --no-headers | sort -nrk 10 | head -100 -
[/tt]
 
Using "top" that would be...
Code:
top -b 100
The "-b" is for batch mode. The "100" is how many processes to list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top