|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to check for and start the Tomcat using a script
Hello Everyone,.
I am a novice with shell scripting and have written some minor shell scripts to copy files and such that. Now I have a requirement to write a shell script to go check if Tomcat running in the same server is up or not, if not then run the Tomcat startup script. Then put this script in a cron. At this point I have few ideas but I just don't know how to bind them into a running script or even know if its the right direction to follow. I would very much appreciate if some one can guide me through this. Any suggestions and ideas would be greatly appreciated. Thanks in Advance. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
bhaire we need input, how could we check a running tomcat process? lets say in order to check a java process which is running on 38080 port we can: Code:
ps -ef | grep java | grep 38080 how do you start tomcat? Like below? you should provide us such input for checking things. Code:
cd $CATALINA_HOME/bin
./startup.sh |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Eagle,
Thanks. I wanted was to create a shell script that will be put in a cronjob to run every say 5 hours daily and the script will check if the Tomcat is up or not if not then start it automatically without having to do it manually. Going your way, as you pointed how to make a shellscrpit read the contents of "ps -ef|grep java" and figure out if Tomcat is up or not if not then run "./startup.sh" any help would be appreciated. Thanks |
|
#4
|
|||
|
|||
|
Sorry for late reply, I hope it'll give you an idea to do it. I checked a production machine which is working over tomcat but i coudlnt be sure what is the right command to see that tomcat is up? but you might do it a few ways. 1. Tomcat's default port is 8080. u can grep it and use port status in comparision loop. Code:
#!/bin/bash
STAT=`netstat -na | grep 8080 | awk '{print $7}'`
if [ "$STAT" = "LISTEN" ]; then
echo "DEFAULT TOMCAT PORT IS LISTENING, SO ITS OK"
elif [ "$STAT" = "" ]; then
echo "8080 PORT IS NOT IN USE SO TOMCAT IS NOT WORKING"
## only if you defined CATALINA_HOME in JAVA ENV ##
cd $CATALINA_HOME/bin
./startup.sh
fi
RESULT=`netstat -na | grep 8080 | awk '{print $7}' | wc -l`
if [ "$RESULT" = 0 ]; then
echo "TOMCAT PORT STILL NOT LISTENING"
elif [ "$RESULT" != 0 ]; then
echo "TOMCAT PORT IS LISTENINS AND SO TOMCAT WORKING"
fi2. You can grep something more reliable than a port number and then you can modify the script according to that data. Maybe you grep "catalina" etc.. Last edited by EAGL€; 09-03-2009 at 06:05 PM.. Reason: forget st to add |
| The Following User Says Thank You to EAGL€ For This Useful Post: | ||
pmt89 (07-28-2011) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks a bunch!!!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help to fingure out what wrong with my tomcat restarting bash script | quyennd | Shell Programming and Scripting | 1 | 01-05-2009 12:47 AM |
| start a script from another tty | moka | Shell Programming and Scripting | 1 | 05-05-2008 08:31 AM |
| Problem with Unix script to start remote Tomcat | shrgh | Shell Programming and Scripting | 2 | 02-08-2008 07:23 AM |
| Start up script | Mr Pink | Shell Programming and Scripting | 1 | 03-09-2007 06:14 AM |
| Script to check for a file, check for 2hrs. then quit | mmarsh | UNIX for Dummies Questions & Answers | 2 | 09-16-2005 02:46 PM |
|
|