The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script creating too many processes. Miller_K Shell Programming and Scripting 3 05-22-2007 12:42 PM
Restart Script chapmana UNIX for Dummies Questions & Answers 1 11-27-2006 11:21 AM
need help to write script to check the process health and automatically restart it dragondad Shell Programming and Scripting 1 10-31-2006 06:16 PM
suspend/restart a process in shell script daneensign Shell Programming and Scripting 1 02-14-2006 12:43 AM
How to restart a script from the top indo1144 Shell Programming and Scripting 2 07-02-2002 08:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-06-2007
_joshua_ _joshua_ is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 7
need help: shell script to restart apache when no. of processes keeps growing

I need a shell script to kill apache and restart it, in case the number of processes keeps growing. The logic is like the below, but I don't know how to get the number and neither the syntax. Could somebody kindly help?

if no_of_processes (ps ax ¦ grep httpd) > 200
then
killall httpd
apachectl start

I'm using Fedora Core3
  #2 (permalink)  
Old 03-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
if [ `ps -fu $USERNAME  | awk '/processname/ { x++ } END{print x}'` > 200 ]
then
 echo "exceeded"
 #do killall and restarting
fi

  #3 (permalink)  
Old 03-06-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
[[ $(ps -ax | grep httpd| wc -l) -gt 200 ]]&& { kill -9 $(ps -ax | grep httpd | awk '{ print $1; }'); apachectl start; }
  #4 (permalink)  
Old 03-06-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
http://httpd.apache.org/docs/2.0/mod...tml#maxclients

Cheers
ZB
  #5 (permalink)  
Old 03-06-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by jacoden
[[ $(ps -ax | grep httpd| wc -l) -gt 200 ]]&& { kill -9 $(ps -ax | grep httpd | awk '{ print $1; }'); apachectl start; }

kill -9???????????????????????????
  #6 (permalink)  
Old 03-06-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
killall httpd -------------> I assumed killing all the httpd processes...
  #7 (permalink)  
Old 03-06-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by jacoden
killall httpd -------------> I assumed killing all the httpd processes...

killall ?????????????????????????

That's the first thing that comes to your mind?

Ever considered trying to stop something in a decent way instead of using kill as first option?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0