Find all services beginning with Oracle and kill if running

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Find all services beginning with Oracle and kill if running

#1 Post by SIMMS7400 » 18 Sep 2016 10:09

Hi Folks -

In certain shut down scripts I have, I need to ensure all Oracle services are down before exiting. The way I do that is have a static text file that lists all of the services relevant for this particular process.

Then, I leverage them like such in my script:

Code: Select all

TIMEOUT /T 60 > NUL
echo ********************************************************>>%logfile%
echo Stop Any Running Hyperion Services %TIME%               >>%logfile%
echo ********************************************************>>%logfile%

SET SVCS_LIST=HYP_SVCS_List.txt

FOR /F %%a IN (%SVCS_LIST%) DO ( SC QUERY %%a | FIND /i "RUNNING" & IF ERRORLEVEL 0 NET STOP %%a )


Is there a way to query all services whos names (not service name) begin with

Code: Select all

Oracle
and then kill if running?

Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find all services beginning with Oracle and kill if running

#2 Post by aGerman » 18 Sep 2016 10:41

What's the difference between Name and Service Name?

Steffen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Find all services beginning with Oracle and kill if running

#3 Post by SIMMS7400 » 18 Sep 2016 10:47

Hi Steffan -

Thanks for the note!

Good question. So, if you navigate to services.msc and open it you'll see the following columns:

Name | Description | Status | Startup Type | Log On As

Now, if you right click on a service and select "Properties" you'll see a field called Service Name and Display Name.

Display Name is what is shown in Column "Name".

For my Oracle Services, Service Name and Display name are not mutually exclusive. BUT, all my services begin with "Oracle" for their display name. Therefore, I figured that would be easiest to code for.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find all services beginning with Oracle and kill if running

#4 Post by aGerman » 18 Sep 2016 11:18

Try if that filters the services you're looking for.

Code: Select all

@echo off &setlocal
set "SERVICE_NAME="
for /f "tokens=1* delims=: " %%i in ('sc query ^| findstr /vbc:" "') do if not defined SERVICE_NAME (set "%%i=%%j") else (
  set "%%i=%%j"
  setlocal EnableDelayedExpansion
  if /i "!DISPLAY_NAME:~,6!"=="Oracle" echo "!SERVICE_NAME!" "!DISPLAY_NAME!"
  endlocal
  set "SERVICE_NAME="
)
pause

Steffen

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Find all services beginning with Oracle and kill if running

#5 Post by Compo » 18 Sep 2016 13:35

have you tried something like this?

Code: Select all

WMIC Service Where "DisplayName Like 'Oracle%' And State='Running'" Call StopService
Edit1 Changed Name to DisplayName after confirmation of output below
Edit2 Added Running validation before calling for a service stop.
Last edited by Compo on 18 Sep 2016 13:45, edited 2 times in total.

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Find all services beginning with Oracle and kill if running

#6 Post by SIMMS7400 » 18 Sep 2016 13:37

Steffen -

Works like a charm! Here is the output :

Code: Select all

"HyS9aifWeb_epmsystem1" "Oracle Hyperion FDM Enterprise Edition - Java Web Application (epmsystem1)" 
"HyS9aps_epmsystem1" "Oracle Hyperion Provider Services - Java Web Application (epmsystem1)"
"HyS9CALC_epmsystem1" "Oracle Hyperion CALC Manager - Java Web Application (epmsystem1)"
"HyS9Disclosure_epmsystem1" "Oracle Hyperion Disclosure Management - Java Web Application (epmsystem1)"
"HyS9eas_epmsystem1" "Oracle Hyperion Administration Services - Java Web Application (epmsystem1)"
"HyS9EPMADataSynchronizer_epmsystem1" "Oracle Hyperion EPMA Data Synchronizer - Java Web Application (epmsystem1)"
"HyS9EPMAServer_epmsystem1" "Oracle Hyperion EPMA Server (epmsystem1)"
"HyS9EPMAWebTier_epmsystem1" "Oracle Hyperion EPMA Web Tier - Java Web Application (epmsystem1)"
"HyS9EssbaseStudio_epmsystem1" "Oracle Hyperion Essbase Studio Server (epmsystem1)"
"HyS9FinancialManagementJavaServer_epmsystem1" "Oracle Hyperion Financial Management - Java Server (epmsystem1)"
"HyS9FinancialManagementWeb_epmsystem1" "Oracle Hyperion Financial Management - Web Tier (epmsystem1)"
"HyS9FoundationServices_epmsystem1" "Oracle Hyperion Foundation Services - Managed Server (epmsystem1)"
"HyS9FRReports_epmsystem1" "Oracle Hyperion Financial Reporting - Java Web Application (epmsystem1)"
"HyS9HsfSrv_epmsystem1" "Oracle Hyperion Strategic Finance - Server (epmsystem1)"
"HyS9HsfWeb_epmsystem1" "Oracle Hyperion Strategic Finance - Java Web Application (epmsystem1)"
"HyS9Planning_epmsystem1" "Oracle Hyperion Planning - Java Web Application (epmsystem1)"
"HyS9RaFrameworkAgent_epmsystem1" "Oracle Hyperion Reporting and Analysis Framework (epmsystem1)"
"HyS9RaFramework_epmsystem1" "Oracle Hyperion Reporting and Analysis Framework - Java Web Application (epmsystem1)"
"HyS9RMIRegistry_epmsystem1" "Oracle Hyperion RMI Registry (epmsystem1)"
"Oracle DRM Service" "Oracle DRM Service"
"OracleProcessManager_EPM_epmsystem1" "Oracle Process Manager (epmsystem1)"
"OracleProcessManager_ohsInstance3193331783" "Oracle Process Manager (ohsInstance3193331783)"


I"ll adjust my script as such now:

Code: Select all

SETLOCAL
set "SERVICE_NAME="
for /f "tokens=1* delims=: " %%i in ('sc query ^| findstr /vbc:" "') do if not defined SERVICE_NAME (set "%%i=%%j") else (
  set "%%i=%%j"
  setlocal EnableDelayedExpansion
  if /i "!DISPLAY_NAME:~,6!"=="Oracle" DO (
  FOR /F %%a IN ("!SERVICE_NAME!") DO ( SC QUERY %%a | FIND /i "RUNNING" & IF ERRORLEVEL 0 NET STOP %%a )
  endlocal
  set "SERVICE_NAME="
)


Thank you!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find all services beginning with Oracle and kill if running

#7 Post by aGerman » 18 Sep 2016 13:48

Great.
Compo's suggestion is worth a try if wmic is available. Double the percent sign in the LIKE Statement when running from within a batch file.

Steffen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Find all services beginning with Oracle and kill if running

#8 Post by SIMMS7400 » 18 Sep 2016 14:22

Will do, I'll test that out now. Thank you both!

Post Reply