•
•
•
•
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
![]() |
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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?
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
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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?????
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?????
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•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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??
•
•
•
•
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
•
•
•
•
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`
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
Similar Threads
- Shell Script for Load monitoring! (Shell Scripting)
- Will ram help server load average? (Linux Servers and Apache)
Other Threads in the Shell Scripting Forum
- Previous Thread: HELP! Im a newbie at scripting
- Next Thread: Shell Script Question


Linear Mode