Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-09-2009, 06:27 PM   #1
Registered: Aug 2007
Posts: 346

Rep: Reputation: 31
check server load with bash

A while back I had some help here with a bash script to check the free ram due to an issue we had, if it hit a level, it would simply email me.

I am looking to do the same this time with the server load. We have a runaway process and I want to do the same thing. A 'w' shows;
load average: 1.49, 1.40, 1.33

and I wish to simply check the load (the 1 second) and if its > x, email me (might throw in more) but does anyone know how to get that varible? The memcheck simply looked like this;

if [ ${MEM_VAL} -gt 450 ]; then
echo MEM_VAL=$MEM_VAL > /tmp/tmpfile
mail -s "message here" my@emailhere < /home/user/memtemp

So until I find this rouge problem, anyone who can help out on this, I greatly appreciate it.
Old 02-09-2009, 09:50 PM   #2
Registered: Aug 2007
Posts: 346

Original Poster
Rep: Reputation: 31
Well with so many other things going on, I managed to get it working, so for the 40+ people who viewed and might care, this is what I have as a band-aid until things are found;

loadavg=`uptime | awk '{print $10}'`
thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`
if [ "$thisloadavg" -ge "10" ]; then
echo "Webserver 5 alert - Load Average $loadavg ($thisloadavg)> /tmp/loadtmp "
mail -s "Alert Sever 5 load GT 10, restarting CF and Apache" < /home/user/loadtmp
killall -9 httpd
/home/user/local/coldfusion/bin/coldfusion stop
sleep 30
/home/user/local/coldfusion/bin/coldfusion start
/home/user/local/apache2/bin/apachectl start

echo "Okay - Load Average $loadavg ($thisloadavg) "


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot load mcrypt extension. Please check your PHP configuration. RMLinux Red Hat 6 07-29-2010 03:18 PM
bash script to check mount is ok procfs Programming 2 01-17-2007 06:19 PM
How to check the bash script syntax? mesh2005 Linux - General 2 04-23-2006 08:22 AM
Health Check / Server Completion Check Software? tells Linux - Enterprise 0 04-20-2006 11:03 AM
bash boundary check noir911 Programming 6 06-24-2005 05:09 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration