Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

restart apache with awk

Status
Not open for further replies.

robschm

Programmer
Mar 26, 2002
10
0
0
DE
have an apache server, that becomes slow some time, bescause of too many user on it (thinks so). now i want to write an awk-script, maybe in connction with c to get the status of the spache server and if its in the "red area" restart it.

please help.

robert
 
AWK is not the right tool for that - sounds very sysadmin-ish task.
Use appropriate "management" tools.....

 
ok, thats right, but look at this:

unix command:
$awk -f myawk

myawk contains:
system(uptime)
$8>5 {system(apachectl restart)}

it should work?!


robert
 
True.
What's the advantage of doing this in AWK VS doing the same [or similar] using other tools [perl, shell..]?
 
its a little advantage in reading the result from uptime, because i know exactly which column it is. but you are right, i can do this with any other language, too.

but what is the best way to do this as small process, that looks looped after five minutes at the server status (uptime) and if the load average is too high, then restart the apache server with command "apachectl restart".

that is, what i want to have.

thanks

robert
 
Here is an idea:


#!/bin/sh
limit=connectlimit
while :
do
connects=`netstat -na | head -n30 | awk -v \
xx=serveraddress ' {
my_connect = xx":80"
if ($0 == my_connect) {
i++
}
print i
}'`
#if too many lines of OP add an end rule; or | sed '1p'
if [ "$connects" -gt "$limit" ] ; then
apachectl restart || echo "Failed to send HUP."
fi
sleep 300
clear
done

Then maybe:
sh scriptname &
Good luck
 
whats about that, there are parse error, why?

BEGIN{
#while(1){
system("uptime > uptime.txt")
getline < &quot;uptime.txt&quot;
#$10>5 {system(&quot;apachectl restart&quot;)}
$10>5 {print &quot;server restart&quot;} #parse error
$10<5 {print &quot;alles ok&quot;} #parse error
system(&quot;sleep 5&quot;)
#}
}
 
where's your conditional?

#---------------------
if ( $10 > 5)
print &quot;server restart&quot;
#---------------------



Also you're confusing what's supposed to be in the BEGIN/END blocks VS what's supposed to be processed as AWK's input.

Also what's the purpose of &quot;sleep&quot;? What are you going to do AFTER &quot;sleep&quot; has expired?

Don't confuse awk with shell/perl paradigms......

I suggest reading awk FAQ on google

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top