Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if Tomcat is running in Windows using the command prompt

Quite simply, how does one determine whether or not Tomcat is running in Windows, using the command prompt?

I am writing a batch script that must do this. This is the Bash version:

RESULT=`netstat -na | grep $2 | awk '{print $7}' | wc -l`

Where $2 is the port.

I am looking for something similar to that. Using Cygwin is out of the question, of necessity this script must be able to run on machines that only have Tomcat.

like image 781
MirroredFate Avatar asked Jun 02 '11 20:06

MirroredFate


People also ask

How do I see Tomcat console in Windows?

The main Apache Tomcat configuration file is at installdir/apache-tomcat/conf/server. xml. Once Apache Tomcat starts, it will create several log files in the installdir/apache-tomcat/logs directory. The main log file is the catalina.

Does Tomcat run on Windows?

Tomcat as a Windows serviceRunning Tomcat as a service allows you to start Tomcat automatically on login, among other things. You can configure the Tomcat service from the desktop by double-clicking the Manager tray icon, navigating to the "General" tab, and choosing "Automatic" for the "Startup type".


2 Answers

Test the status of the Tomcat Service with the SC command. MJB already suggested to test the service status with SC, yet another batch script (without FOR loop) for testing the status:

@ECHO OFF
SC query tomcat5 | FIND "STATE" | FIND "RUNNING" > NUL
IF ERRORLEVEL 1 (
    ECHO Stopped
) ELSE (
    ECHO Running
)

If you are not sure if the service name is tomcat5 you can list all service names with

SC query state= all | FIND "SERVICE_NAME"
like image 121
Christian Ammer Avatar answered Oct 29 '22 04:10

Christian Ammer


You could use tasklist to check if the tomcat executable is running. For example:

@echo off
tasklist /FI "IMAGENAME eq tomcat.exe" | find /C /I ".exe" > NUL
if %errorlevel%==0 goto :running

echo tomcat is not running
goto :eof

:running
echo tomcat is running

:eof

It is also possible to check a remove server using the options /S, /U and /P. See tasklist /? for details.

like image 30
wimh Avatar answered Oct 29 '22 04:10

wimh