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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

monitor script

Status
Not open for further replies.

nareshb

MIS
Jun 17, 2008
2
Hi,

Can we write a shell script to monitor if
the webserver instance is running or not. if
so, please provide me information on how to do so?


Thank You
 
depends on what shows up when you run ps -ef

intranet 23945 15270 0 00:20:04 ? 53:03 ns-httpd -d /opt/iplanet/https-prods/config
intranet 24277 15254 0 00:30:04 ? 0:15 ns-httpd -d /opt/iplanet/https-auth/config
root 15247 15246 0 Mar 27 ? 1:03 ns-httpd -d /opt/iplanet/https-admserv/config
root 4347 10003 1 14:19:50 pts/ta 0:00 grep httpd
intranet 23675 15262 0 00:10:07 ? 180:13 ns-httpd -d /opt/iplanet/https-prod/config

if you can find something unique in the results,
yes you can.

for example in a script:
STATUS=`ps -ef|grep httpd|grep /opt/iplanet/https-prods`
if test -z $STATUS
then
then restart webserver here
fi

Robert
Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Something like this running from the crontab will do it for you. You may have to change the bit where it starts the server to suit the path on your server. This is assuming you are running apache.

#!/bin/ksh
HTTP=`ps -ef | grep [h]ttp|wc -l`
if [ $HTTP -lt 1 ] ; then
/usr/local/apache/bin/apachectl start #(or "startssl" if secure site)
fi

Hope it helps. IBM Certified Specialist - MQSeries
IBM Certified Specialist - AIX 5 pSeries System Administration
 
Should not be a problem. All you need to do is to write a script that tests for the PID of the web-server. If it is running, then no worries. If it stops, have an email sent to you.

I would set this up as a cron job to run every 10 or 15 minutes (more often if you need)

#!/bin/sh
#
#Script to test for web-server
#
#
if ps -aux | grep "nameofprocess" ; then
exit
else
mail -S "Web Server is down" username
fi


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top