I am conserned about this, because when the load on the system is high, it slows everything down, one cause for this is a process in a loop that is consumoing allot of resources.
This will give you the uptime in format "up xx days". From there, you can use "cut" or "awk" to pull out individual fields.
One word of caution...don't treat UNIX like Windows. Don't just choose to reboot when the system acts "weird". Your best bet is to research the problem and repair it. If you are looking into a CPU hog, see why it is doing it.
I have a Perl script which does something like that, would you be interested? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
Hmm, script is at work, and I'm out of the office all week. This is the basis of it though, hope it's enough to get you started.
while(){
open(UPT,"uptime|" or die "oops...\n$!\n";
while(<UPT>){
if(/average:/){
$averages = $';
@averages_array = split(/,/,$averages);
# next line checks load average against some
# value, insert your own value instead of 2
if(@averages_array[0] > 2){
open(SM,"|sendmail you@your.office.com" or die "oops again...\n$!\n";
print SM "Subject: Load average too high...\n\n";
print SM "Looks a bit busy here...\n";
close(SM);
}
}
}
sleep(60);
} Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.