Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1628
  • Last Modified:

Find catalina_home in windows for tomcat 6

My environment currently has 50 tomcats setup in one hard disk.

I am creating a batch script to find the status of the tomcat services.
I am able to fetch the service status using:

echo net start | find "%tomcatname%"
if %ERRORLEVEL% == 2 goto trouble
if %ERRORLEVEL% == 1 goto stopped
if %ERRORLEVEL% == 0 goto started
echo unknown status
goto end

I would like to find CATALINA_HOME setup for each of these services as well. How can I do that?
0
nainil
Asked:
nainil
  • 10
  • 8
  • 3
1 Solution
 
oBdACommented:
Okay, I know next to nothing about Tomcat, but I'll bite. The following might work; just pass it the type (whether you're specifying the service display name or the short name) and the name of the service in the command line:
@echo off
setlocal enabledelayedexpansion
if /i not "%~1"=="-Key" (
	if /i not "%~1"=="-Display" (
		echo Syntax: %~nx0 { -Key ^<Service Key Name^> ^| -Display ^<Service Display Name^> }
		goto :eof
	)
)
set NameType=%~1
set Service=%~2
if /i "%NameType%"=="-Display" (
	for /f "tokens=1* delims== " %%a in ('sc.exe GetKeyName "%Service%" ^| find "Name ="') do set Service=%%b
)
set ServiceBaseKey=HKLM\System\CurrentControlSet\Services
set State=UNKNOWN
set CatalinaHome=UNKNOWN
for /f "tokens=3 delims=: " %%a in ('sc.exe query "%Service%" ^| find "STATE"') do set State=%%a
for /f "tokens=1* delims==" %%a in ('reg.exe query "%ServiceBaseKey%\%Service%\Parameters" ^| find "-Dcatalina.home="') do set CatalinaHome=%%b
echo Status report for service %Service%:
echo Service state: %State%
echo Catalina home: %CatalinaHome%

Open in new window

0
 
nainilAuthor Commented:
oBdA:

Thanks for the code. I am sorry, but, I am not a batch file expert.

When you say "pass it the type ", which line of code are you referring to?
0
 
oBdACommented:
What you're currently using is the service's display name, so just run it as
Whatever.cmd -display %TomcatName%
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nainilAuthor Commented:
Ahh, I see. let me try
0
 
nainilAuthor Commented:
this allowed me to get the service status. Great.

but, I am unable to get the catalina_home. However, i see ImagePath which can help me get what I want.

My registry lists:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\tomcat6]
"ImagePath"=C:\App\tomcat6\bin\tomcat6.exe //RS//tomcat6

It lists the executable for that service. If we can extract the string "C:\App\tomcat6\" from ImagePath, it should be equivalent to Catalina_home.
0
 
oBdACommented:
Can you export the "Parameters" key under ...\services\tomcat6 and post it?
0
 
nainilAuthor Commented:
That section is blank. I checked in two systems.. Windows 7 and Windows 2003.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\tomcat6]
"Type"=dword:00000010
"Start"=dword:00000003
"ErrorControl"=dword:00000001
"ImagePath"=hex(2):43,00,3a
"DisplayName"="Apache Tomcat tomcat6"
"ObjectName"="LocalSystem"
"Description"="Apache Tomcat tomcat6"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\tomcat6\Parameters]

Open in new window


the ImagePath shows in HEX when exporting from registry. However, in registry, when we are viewing data, it shows in English
0
 
oBdACommented:
How's this?
@echo off
setlocal enabledelayedexpansion
if /i not "%~1"=="-Key" (
	if /i not "%~1"=="-Display" (
		echo Syntax: %~nx0 { -Key ^<Service Key Name^> ^| -Display ^<Service Display Name^> }
		goto :eof
	)
)
set NameType=%~1
set Service=%~2
if /i "%NameType%"=="-Display" (
	for /f "tokens=1* delims== " %%a in ('sc.exe GetKeyName "%Service%" ^| find "Name ="') do set Service=%%b
)
set ServiceBaseKey=HKLM\System\CurrentControlSet\Services
set State=UNKNOWN
set ImagePath=UNKNOWN
for /f "tokens=3 delims=: " %%a in ('sc.exe query "%Service%" ^| find "STATE"') do set State=%%a
for /f "tokens=2* delims==" %%a in ('reg.exe query "%ServiceBaseKey%\%Service%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b
call :Parse %ImagePath%
echo Status report for service %Service%:
echo Service state: %State%
echo Catalina home: %CatalinaHome%
goto :eof
:Parse
set CatalinaHome=%~1
goto :eof

Open in new window

0
 
nainilAuthor Commented:
Sorry, does not work.

This is the output.

C:\Users\user1\Desktop>catalina.bat -display tomcat6
Status report for service tomcat6:
Service state: STOPPED
Catalina home: UNKNOWN

C:\Users\user1\Desktop>
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
How are you starting these tomcat instances? Some script I presume? Can you show some details about that?
0
 
nainilAuthor Commented:
This is the catalina.bat which i believe is called to start tomcat.
Here you go:

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

if "%OS%" == "Windows_NT" setlocal
rem ---------------------------------------------------------------------------
rem Start/Stop Script for the CATALINA Server
rem
rem Environment Variable Prequisites
rem
rem   CATALINA_HOME   May point at your Catalina "build" directory.
rem
rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
rem                   of a Catalina installation.  If not present, resolves to
rem                   the same directory that CATALINA_HOME points to.
rem
rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
rem                   or "run" command is executed.
rem
rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
rem                   the JVM should use (java.io.tmpdir).  Defaults to
rem                   %CATALINA_BASE%\temp.
rem
rem   JAVA_HOME       Must point at your Java Development Kit installation.
rem                   Required to run the with the "debug" argument.
rem
rem   JRE_HOME        Must point at your Java Runtime installation.
rem                   Defaults to JAVA_HOME if empty.
rem
rem   JAVA_OPTS       (Optional) Java runtime options used when the "start",
rem                   "stop", or "run" command is executed.
rem
rem   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
rem                   (JSSE) installation, whose JAR files will be added to the
rem                   system class path used to start Tomcat.
rem
rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
rem                   command is executed. The default is "dt_shmem".
rem
rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. The default is "jdbconn".
rem
rem   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. Specifies whether JVM should suspend
rem                   execution immediately after startup. Default is "n".
rem
rem   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
rem                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
rem                   and JPDA_SUSPEND are ignored. Thus, all required jpda
rem                   options MUST be specified. The default is:
rem
rem                   -Xdebug -Xrunjdwp:transport=%JPDA_TRANSPORT%,
rem                       address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
rem
rem $Id: catalina.bat 656834 2008-05-15 21:04:04Z markt $
rem ---------------------------------------------------------------------------

rem Guess CATALINA_HOME if not defined
set CURRENT_DIR=%cd%
if not "%CATALINA_HOME%" == "" goto gotHome
set CATALINA_HOME=%CURRENT_DIR%
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
cd ..
set CATALINA_HOME=%cd%
cd %CURRENT_DIR%
:gotHome
if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
echo The CATALINA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end
:okHome

rem Get standard environment variables
if "%CATALINA_BASE%" == "" goto gotSetenvHome
if exist "%CATALINA_BASE%\bin\setenv.bat" call "%CATALINA_BASE%\bin\setenv.bat"
goto gotSetenvBase
:gotSetenvHome
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
:gotSetenvBase

rem Get standard Java environment variables
if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
echo Cannot find %CATALINA_HOME%\bin\setclasspath.bat
echo This file is needed to run this program
goto end
:okSetclasspath
set BASEDIR=%CATALINA_HOME%
call "%CATALINA_HOME%\bin\setclasspath.bat" %1
if errorlevel 1 goto end

rem Add on extra jar files to CLASSPATH
if "%JSSE_HOME%" == "" goto noJsse
set CLASSPATH=%CLASSPATH%;%JSSE_HOME%\lib\jcert.jar;%JSSE_HOME%\lib\jnet.jar;%JSSE_HOME%\lib\jsse.jar
:noJsse
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\bootstrap.jar

if not "%CATALINA_BASE%" == "" goto gotBase
set CATALINA_BASE=%CATALINA_HOME%
:gotBase

if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
set CATALINA_TMPDIR=%CATALINA_BASE%\temp
:gotTmpdir

if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuli
set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
:noJuli

rem ----- Execute The Requested Command ---------------------------------------

echo Using CATALINA_BASE:   %CATALINA_BASE%
echo Using CATALINA_HOME:   %CATALINA_HOME%
echo Using CATALINA_TMPDIR: %CATALINA_TMPDIR%
if ""%1"" == ""debug"" goto use_jdk
echo Using JRE_HOME:        %JRE_HOME%
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME:       %JAVA_HOME%
:java_dir_displayed

set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=

if not ""%1"" == ""jpda"" goto noJpda
set JPDA=jpda
if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
set JPDA_TRANSPORT=dt_shmem
:gotJpdaTransport
if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=jdbconn
:gotJpdaAddress
if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
set JPDA_SUSPEND=n
:gotJpdaSuspend
if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
:gotJpdaOpts
shift
:noJpda

if ""%1"" == ""debug"" goto doDebug
if ""%1"" == ""run"" goto doRun
if ""%1"" == ""start"" goto doStart
if ""%1"" == ""stop"" goto doStop
if ""%1"" == ""version"" goto doVersion

echo Usage:  catalina ( commands ... )
echo commands:
echo   debug             Start Catalina in a debugger
echo   debug -security   Debug Catalina with a security manager
echo   jpda start        Start Catalina under JPDA debugger
echo   run               Start Catalina in the current window
echo   run -security     Start in the current window with security manager
echo   start             Start Catalina in a separate window
echo   start -security   Start in a separate window with security manager
echo   stop              Stop Catalina
echo   version           What version of tomcat are you running?
goto end

:doDebug
shift
set _EXECJAVA=%_RUNJDB%
set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
goto execCmd

:doRun
shift
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
goto execCmd

:doStart
shift
if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA=start "Tomcat" %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%
:gotTitle
if not ""%1"" == ""-security"" goto execCmd
shift
echo Using Security Manager
set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
goto execCmd

:doStop
shift
set ACTION=stop
set CATALINA_OPTS=
goto execCmd

:doVersion
%_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
goto end


:execCmd
rem Get remaining unshifted command line arguments and save them in the
set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:doneSetArgs

rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end

:end

Open in new window

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Yes, that is the script to start tomcat but how do you call it? You say you have 50 running instances?
0
 
nainilAuthor Commented:
well, we have services setup for each of them. We call "net start <servicename>"... does that help?
0
 
oBdACommented:
Sorry, copy and paste error. In line 18, remove the " delims==" at the beginning, so that only "tokens=2*" remains:
for /f "tokens=2* delims==" %%a in ('reg.exe query "%ServiceBaseKey%\%Service%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You can use Process Explorer for that, but it's a GUI. It can show for each process what the environment variables are when the process was started.
0
 
oBdACommented:
Missed that you don't want the whole imagepath, but only the part before the \bin:
@echo off
setlocal enabledelayedexpansion
if /i not "%~1"=="-Key" (
	if /i not "%~1"=="-Display" (
		echo Syntax: %~nx0 { -Key ^<Service Key Name^> ^| -Display ^<Service Display Name^> }
		goto :eof
	)
)
set NameType=%~1
set Service=%~2
if /i "%NameType%"=="-Display" (
	for /f "tokens=1* delims== " %%a in ('sc.exe GetKeyName "%Service%" ^| find "Name ="') do set Service=%%b
)
set ServiceBaseKey=HKLM\System\CurrentControlSet\Services
set State=UNKNOWN
set ImagePath=UNKNOWN
for /f "tokens=3 delims=: " %%a in ('sc.exe query "%Service%" ^| find "STATE"') do set State=%%a
for /f "tokens=2*" %%a in ('reg.exe query "%ServiceBaseKey%\%Service%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b
call :Parse %ImagePath%
echo Status report for service %Service%:
echo Service state: %State%
echo Catalina home: %CatalinaHome%
goto :eof
:Parse
set CatalinaHome=%~dp1
set CatalinaHome=%CatalinaHome:bin\=%
goto :eof

Open in new window

0
 
nainilAuthor Commented:
Thank you. it works perfectly.
I am trying to incorporate it in my batch script. I may seek your assistance again if I face any issues.
0
 
nainilAuthor Commented:
I did some changes:
to remove the trailing "\" in the image path
Combining your code with my code


All seems to work fine, but, i get an error message in line 21. Not sure what is causing the same. SET was unexpected at this time.

Any help is appreciated.

C:\Users\Desktop>cleartomcat.bat

What is the tomcat service name? tomcat6

checking status of tomcat6
   Apache Tomcat tomcat6
tomcat6 service is running. Stopping it now.

The Apache Tomcat tomcat6 service was stopped successfully.

checking status of tomcat6
tomcat6 is stopped

clearing work folder "C:\eClinicalWorks\tomcat6\work"
clearing tomcat logs "C:\eClinicalWorks\tomcat6\logs"

starting tomcat6
The Apache Tomcat tomcat6 service is starting.
The Apache Tomcat tomcat6 service was started successfully.

SET was unexpected at this time.

Open in new window


Here is the code which I have so far.

@echo off

rem Clear Logs - version 08/24/2012 13:20 pm

echo.
if "%1"=="" goto askq

:askq
set /p tomcatname=What is the tomcat service name? 
echo.
if "%tomcatname%"=="" goto askq
goto gettomcatdirectory

:gettomcatdirectory
set ServiceBaseKey=HKLM\System\CurrentControlSet\Services
set ImagePath=UNKNOWN
for /f "tokens=2*" %%a in ('reg.exe query "%ServiceBaseKey%\%tomcatname%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b
call :Parse %ImagePath%

:Parse
set tomcatdirectory=%~dp1
set tomcatdirectory=%tomcatdirectory:bin\=%
IF %tomcatdirectory:~-1%==\ SET tomcatdirectory=%tomcatdirectory:~0,-1%
goto checkstatus


:checkstatus
echo checking status of %tomcatname%
net start | find "%tomcatname%"
if %ERRORLEVEL% == 2 goto trouble
if %ERRORLEVEL% == 1 goto stopped
if %ERRORLEVEL% == 0 goto started
echo unknown status
goto end

:trouble
echo %tomcatname% is in troubled state. Please kill process manually
goto end

:started
echo %tomcatname% service is running. Stopping it now.
net stop %tomcatname%
goto checkstatus

:stopped
echo %tomcatname% is stopped
goto clearlogs

:clearlogs
echo clearing work folder "%tomcatdirectory%\work"
del "%tomcatdirectory%\work\*.*" /Q
rmdir "%tomcatdirectory%\work\Catalina" /S /Q

echo clearing tomcat logs "%tomcatdirectory%\logs"
del "%tomcatdirectory%\logs\*.*" /Q

echo starting %tomcatname%
net start %tomcatname%

:end

Open in new window

0
 
oBdACommented:
Try the script below. Your current status determination won't work as you seem to have imagined it; "find" will return either errorlevel 0 (when it finds the string) or errorlevel 1 (when it doesn't), but never 2. The "parse" part in my script is a function that can't be put in the middle of the script. Then I added support to actually pass the name in the command line.
@echo off

rem Clear Logs - version 08/24/2012 13:20 pm

echo.
if not "%1"=="" (
	set tomcatname=%~1
	goto gettomcatdirectory
)
:askq
set /p tomcatname=What is the tomcat service name? 
echo.
if "%tomcatname%"=="" goto askq

:gettomcatdirectory
set ServiceBaseKey=HKLM\System\CurrentControlSet\Services
set ImagePath=UNKNOWN
for /f "tokens=2*" %%a in ('reg.exe query "%ServiceBaseKey%\%tomcatname%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b
call :Parse %ImagePath%
echo tomcatdirectory is %tomcatdirectory%

:checkstatus
echo checking status of %tomcatname%
set State=UNKNOWN
for /f "tokens=3 delims=: " %%a in ('sc.exe query "%Service%" ^| find "STATE"') do set State=%%a
if /i "%State%"=="RUNNING" goto started
if /i "%State%"=="STOPPED" goto stopped
echo %tomcatname% is in a troubled state. Please kill process manually
goto end

:started
echo %tomcatname% service is running. Stopping it now.
net stop "%tomcatname%"
if errorlevel 1 (
	echo Couldn't stop %tomcatname%. Please kill process manually.
)
goto end

:stopped
echo %tomcatname% is already stopped

:clearlogs
echo clearing work folder "%tomcatdirectory%\work"
del "%tomcatdirectory%\work\*.*" /Q
rmdir "%tomcatdirectory%\work\Catalina" /S /Q

echo clearing tomcat logs "%tomcatdirectory%\logs"
del "%tomcatdirectory%\logs\*.*" /Q

echo starting %tomcatname%
net start "%tomcatname%"
if errorlevel 1 (
	echo Couldn't start %tomcatname%. Please investigate.
)
:end

REM ====================================================================
goto :eof
REM Functions from here on
REM ====================================================================

:Parse
set tomcatdirectory=%~dp1
set tomcatdirectory=%tomcatdirectory:\bin\=%
goto :eof

Open in new window

0
 
nainilAuthor Commented:
This is terrific.

I have one question... What does these lines of code mean.. syntactically?
a. for /f "tokens=2*" %%a in ('reg.exe query "%ServiceBaseKey%\%tomcatname%" /v "ImagePath" ^| find /i "ImagePath"') do set ImagePath=%%b

b. What is %%a and /i?
for /f "tokens=3 delims=: " %%a in ('sc.exe query "%Service%" ^| find "STATE"') do set State=%%a
if /i "%State%"=="RUNNING" goto started
if /i "%State%"=="STOPPED" goto stopped
0
 
oBdACommented:
First one takes the output of the reg.exe command, finds the line with "ImagePath" in it, and takes the third token (delimited by the default of space).
%%a is the "for" loop variable.
"if /i" makes a case insensitive comparison.
Nice scripting resource: http://www.robvanderwoude.com/
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now