User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 392,088 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,889 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 1324 | Replies: 6
Reply
Join Date: May 2007
Posts: 3
Reputation: jibsonline is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jibsonline jibsonline is offline Offline
Newbie Poster

Help Determening load average.

  #1  
May 2nd, 2007
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???

Regard
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Determening load average.

  #2  
May 2nd, 2007
why only 10? and why would you want to restart Apache based on load avg?

Load average is a calculation loosely based on the amount of time a process has to wait for the CPU, I have personally seen my BSD boxes hit an excess of 600 load average before choking. You should be looking at % idle not the load average. All of this data is available to you via the /proc filesystem(on Linux).

A better measurement would be to use either Apache (remotely if course) or count the amount of processes that are happening. You can also use a monitoring service or program to "ping" the server at a predetermined interval, or grab a web page, and notify you based on response time. or even better, fix whatever it is that is causing you to have these runaway processes.

It has been my experience that it is never good to blindly restart processes like this. What happens if there is a syntax error in one of the config file? or maybe some permissions changed on a logfile and Apache cant get a lock on it?
Last edited by sn4rf3r : May 2nd, 2007 at 3:17 pm. Reason: spelling
Reply With Quote  
Join Date: May 2007
Posts: 3
Reputation: jibsonline is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jibsonline jibsonline is offline Offline
Newbie Poster

Question Re: Determening load average.

  #3  
May 2nd, 2007
I'm actually not trying to stop the webserver. There is a page to be loaded id the load average is high on another server. i'm able to get the value from an "uptime" command. but the value i get is in a string format. So when i try comparing the value

uptime|gawk '{ print $12 }' > load

while read Inbr
do
echo $Inbr
if [ $Inbr -gt 77 ]; then
echo "Greater than 77"
else
echo "Less or equal to 77"
fi
done < load

I get an error
0.04
./test: line 7: [: 0.04: integer expression expected
Less or equal to 77

How can i change the value to integer type?????
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Determening load average.

  #4  
May 2nd, 2007
How about this?
uptime|gawk  '{ print $12 }' | tr -d '.'   > load
while read Inbr
  do
    echo $Inbr
    if [ `bc -l <<< $Inbr` -gt 77 ]; then
      echo "Greater than 77"
      else
         echo "Less or equal to 77"
      fi
done < load
Reply With Quote  
Join Date: May 2007
Posts: 3
Reputation: jibsonline is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jibsonline jibsonline is offline Offline
Newbie Poster

Question Re: Determening load average.

  #5  
May 3rd, 2007
Thanks!!! It worked fine. I need a minor help now. I need to store a falg value to a file. I do it by redirecting the value. But how can i retrieve the value back from the file to a variable?? For eg: I have a file "flag" which has the value "0" in it. How do i pass the value to a variable in the script??
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Determening load average.

  #6  
May 3rd, 2007
Originally Posted by jibsonline View Post
Thanks!!! It worked fine. I need a minor help now. I need to store a falg value to a file. I do it by redirecting the value. But how can i retrieve the value back from the file to a variable?? For eg: I have a file "flag" which has the value "0" in it. How do i pass the value to a variable in the script??

use cat
Reply With Quote  
Join Date: Sep 2006
Location: NYC
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: Determening load average.

  #7  
May 3rd, 2007
Originally Posted by jibsonline View Post
Thanks!!! It worked fine. I need a minor help now. I need to store a falg value to a file. I do it by redirecting the value. But how can i retrieve the value back from the file to a variable?? For eg: I have a file "flag" which has the value "0" in it. How do i pass the value to a variable in the script??

var=`cat file`
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 12:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC