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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UPTIME on UNIX

Status
Not open for further replies.

Genka

MIS
Jul 15, 2001
20
0
0
US
Would any one have a script to check the Uptime periodiclly,
and email a message if the Uptime gets above a certain point? Thanks in Advance
 
Why are you concerned about this ?

/> uptime
04:04PM up 346 days, 21:46, 1 user, load average: 0.37, 0.17, 0.10
 
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.
 
Well, put the following line in a script:

uptime |cut -f1 -d","|cut -c10-

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.

Just my opinion.

Bill.
 
Genka,

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.
 
Yes mike, Can you plese send.
Thank you very much.
 
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,&quot;|sendmail you@your.office.com&quot;) or die &quot;oops again...\n$!\n&quot;;
print SM &quot;Subject: Load average too high...\n\n&quot;;
print SM &quot;Looks a bit busy here...\n&quot;;
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top