How to check for and start the Tomcat using a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check for and start the Tomcat using a script
# 1  
Old 09-03-2009
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.
# 2  
Old 09-03-2009
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

# 3  
Old 09-03-2009
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
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 07:05 PM.. Reason: forget st to add
This User Gave Thanks to EAGL€ For This Post:
# 5  
Old 09-04-2009
Thanks a bunch!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Shell Programming and Scripting

Montioring Script Tomcat catalina.out

Hi, I need to monitor the tomcat log file called "Catalina.out" for any errors like out of memory,JDBC exceptions,broken pipe any other errors and exceptions The script should monitor this file and send a mail instantly and create a text file with errors day to day. Iam using Solaris... (3 Replies)
Discussion started by: chaithanyaa
3 Replies

3. Solaris

Tomcat..Unable to deploy application remotely in tomcat

Hi, We have upgrade tomcat from 5.0.20 to 7.0.33 and made changes to server.xml file according to newer version.. how ever the upgrade went fine and now i am unable to deploy application remotely.. it is giving 403 access denied error.. we have seperate appbase directory mentioned in server.xml..... (0 Replies)
Discussion started by: phani4u
0 Replies

4. Shell Programming and Scripting

Help scripting to start, check, and restart processes

Here it goes from my unexperienced point of view. I am using CentOS 5.6. I have a Java based server that needs to be running 24/7/365. To begin from the machine the server is on rebooting; I SSH in to a shell, cd to the server dir, screen -S server1, and execute ./exec (listed below) in the screen.... (12 Replies)
Discussion started by: MacG32
12 Replies

5. UNIX for Advanced & Expert Users

Is it Possible to Start Tomcat Manager using command prompt!

Hi All, wget http://<username>:<password>@<hostname>:<port>/manager/list -O - -q using this command i can able to stop , start , reload everything i can able to do once i start the tomcat , now i have some doubt legends. 1. Is this is a secure way using wget to start, stop, reload the... (0 Replies)
Discussion started by: anishkumarv
0 Replies

6. Shell Programming and Scripting

tomcat automaticaly stop in menu script

i have a problem with the code I created (see below). a. when I logged in as root and su to tomcat, i can execute all options. when I press X, it will exit properly. b. when I logged in directly as user1, I can execute also all options. if I press X i will logout automatically to putty.... (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. Shell Programming and Scripting

UNIX script to check file and start the informatica server

Hi Rockers, I hope u r dng good one. I have a one question is in unix with informatica . I need a unix script to check whether particular file exists in the folder , If it means we have a informatica server , so we can start the informatica server by accessing that file. Every week we have... (0 Replies)
Discussion started by: gurukrishnan
0 Replies

8. Solaris

How to start tomcat with 2 jdk?

Current platform: Sun OS 5.9 Solaris isainfo -v 64-bit sparcv9 applications 32-bit sparc applications Problem: Fail to start tomcat server ps -ef | grep tomcat nothing displays... Steps: Installed jakarta-tomcat-5.0.30 Installed jdk 1.6 and set path in profile... (11 Replies)
Discussion started by: sbox
11 Replies

9. Web Development

Allow multiple users to start/stop tomcat

Hi, I have the user who runs tomcat: tomcat:tomcats I want to have another user who will be able to start and stop tomcat process. Is this possible? Thanks, Bianca (1 Reply)
Discussion started by: potro
1 Replies

10. Shell Programming and Scripting

Problem with Unix script to start remote Tomcat

I have Tomcat installed on a Unix box and I need to start it remotely from another Unix box. Tomcat is started using a script. When this script is run locally everything is fine. When I run the same script from remote box, tomcat starts but the command running the script does not terminate.:( ... (2 Replies)
Discussion started by: shrgh
2 Replies
Login or Register to Ask a Question