The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
average value su_in99 UNIX for Dummies Questions & Answers 2 03-10-2007 01:41 PM
Need help in wrting Load Script for a Load-Resume type of load. ankitgupta Shell Programming and Scripting 1 11-10-2006 12:46 AM
Load Average Heathe_Kyle UNIX for Dummies Questions & Answers 3 10-24-2006 04:57 PM
High cpu load average squid04 Red Hat 2 09-27-2006 09:07 AM
load average gfhgfnhhn UNIX for Advanced & Expert Users 0 09-12-2006 12:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-02-2007
jibsonline jibsonline is offline
Registered User
  
 

Join Date: May 2007
Posts: 9
Smile Determening load average.

Hi,
I'm new to shell scripting. I need to make a script to add on to my cronjobs.


The script must get the value of load average from my server and if its greater than 10 it should stop my apache service. I cant find a way to get the value of load average in integer type to do the check. Any help??? Can anyone give me a sample script???

Jibu
  #2 (permalink)  
Old 05-02-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
You can get load average by "uptime" command, output will be :
Quote:
15:42:32 up 18 days, 21:18, 0 users, load average: 1.26, 1.21, 1.06
These numbers : "1.26, 1.21, 1.06" are the load average of the last 1, 5, 15 minutes.
and the logic would be something like :
Code:
#!/bin/bash

load=`uptime|awk '{print $12}'
if [ $load -gt 10 ]; then 
   echo Stopping httpd server due to high system load.... >> /path/to/apache-logs
/etc/init.d/httpd stop
fi
but this will depend very much on your system config files and OS.
  #3 (permalink)  
Old 05-02-2007
jibsonline jibsonline is offline
Registered User
  
 

Join Date: May 2007
Posts: 9
I get an error running the script

[: -gt: unary operator expected

Jibu
  #4 (permalink)  
Old 05-02-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Jibu,
Be careful, you may be breaking one of the Unix forum rule:
Code:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.
  #5 (permalink)  
Old 05-03-2007
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
Yes, do not cross-post please.
This was a hidden catch, just to see if you will get my example verbatim. Why I did that ? If you want to run such script, means you have root priviledges, means someone at your organization trust you, means you're not supposed to be a simple user.
I would also assume that the server you're running has only apache there, hence you want to switch it off when high load is determined. If not, how you can be sure that this is the application that causes the problem ?
In regards to the script - see "man test" for more information. Of course you can compare integer to integer, but bash doesn't have good handling of floating points generated from uptime. Therefore there are few solutions :
using awk in this manner :
Code:
if echo $loadhttpd | awk '{ if ($loadhttpd < '10') {print "10 is bigger then httpload"}}'; then
or using the korn shell, as it has floating point arithmetic since 1993.
I won't write more code, please, try think to about it, and be a real admin, not a user.
Regards and no bad feelings.
Closed Thread

Bookmarks

Tags
load average, performance

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0