How to check for and start the Tomcat using a script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

How to check for and start the Tomcat using a script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-03-2009
bhaire bhaire is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 9 November 2009, 3:35 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 09-03-2009
EAGL€ EAGL€ is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 2 September 2014, 3:09 AM EDT
Location: izmir
Posts: 314
Thanks: 29
Thanked 13 Times in 13 Posts
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  
Old 09-03-2009
bhaire bhaire is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 9 November 2009, 3:35 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 09-03-2009
EAGL€ EAGL€ is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 2 September 2014, 3:09 AM EDT
Location: izmir
Posts: 314
Thanks: 29
Thanked 13 Times in 13 Posts
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"
fi

2. 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  
Old 09-04-2009
bhaire bhaire is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 9 November 2009, 3:35 PM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a bunch!!!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 07:27 AM.