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

You can get load average by "uptime" command, output will be :

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 :

#!/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.

I get an error running the script

[: -gt: unary operator expected

Jibu

Jibu,
Be careful, you may be breaking one of the Unix forum rule:

(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.

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 :

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.