On Wed, May 02, 2007 at 09:20:23AM +0100, Jibu N Chacko wrote:
> 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 "top" or "uptime" and 
> check it. If its greater than 10 it should stop my apache service. I cant 
> find a way to get the value od load average in integer type to do the check. 
> Any help???
>    

That's an interesting one.  Which of the three load averages?  I think
some combo of cut and awk might get you that figure, at least of one of
them.  


If you use cut, at least on FreeBSD, I think you have to use -d ' ' to
make the delineator a space.  

Ok in FreeBSD, using cut -d ' ' field 12 was 1 minute, field 13 5
minutes field 14 15 minutes.  Then to get an integer, I guess you could
use cut again with . as the delineator.  Hrrm, let me see.  Yup, ugly
but it works.

uptime | cut -d ' ' -f 12 | cut -d . -f 1

There *has* to be a more elegant way to do that, but I'm at work, so I
have my excuse for not trying harder.  

I don't know if Cameron's on this list, if he is, and sees this, he'll
give you something much better.  Ajay's another if he's here.  


Hope this at least gets you started.  After that, I guess a simple if
else type thing, but as far as I can tell, you just need to figure out a
way to get that load average.


-- 

Scott

GPG KeyID EB3467D6
( 1B848 077D 66F6 9DB0 FDC2  A409 FA54 D575 EB34 67D6)
gpg --keyserver pgp.mit.edu --recv-keys EB3467D6

Giles: I'll have you know that I have very, um, many
relaxing hobbies.
Buffy: Such as?
Giles: Well, um...I enjoy cross-referencing.
Buffy: Do you stuff your own shirts or do you send 'em out?


To unsubscribe from this list, please email [EMAIL PROTECTED] & you will be 
removed. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/LINUX_Newbies/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/LINUX_Newbies/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to