Checking several services with one single test

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
AlexL
Posts: 62
Joined: Tue Jul 18, 2006 9:56 am
Location: Switzerland

Checking several services with one single test

Post by AlexL »

In this shell script test I am using the Microsoft's SC.EXE command line utility:

Code: Select all

@ECHO OFF
setlocal enabledelayedexpansion
SET not_running=
SET skip=
SET count=
FOR /F "tokens=2" %%a IN ('SC \\%1 QUERY ^| FIND /I "SERVICE_NAME: "') DO SET "var=!var! %%a"
FOR %%a IN (%*) DO CALL :next %%a %var%
IF NOT "%not_running%"=="" (
   ECHO ScriptRes:Bad:Missing: %not_running%
) ELSE (
   ECHO ScriptRes:Ok:%count% of %count% OK
)
GOTO :EOF
:next
IF NOT DEFINED skip SET skip=1 & GOTO :EOF
SET match=
SET serviceut=%1
:loop
IF /I %serviceut%==%2 SET match=1 & SET /A count=count+1
SHIFT
IF NOT %2.==. GOTO :loop
IF NOT DEFINED match SET not_running=%not_running% %serviceut%
with these Params:

<SERVER> <service> <service> ....

where <service> is the "service name" (one word, w/o blanks), not the "display name". On Bad status, the Reply lists the services which do not run.

Alex
KS-Soft
Posts: 12869
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Thank you

Regards
Alex
rathimeena
Posts: 3
Joined: Wed Jan 09, 2013 9:51 pm

Post by rathimeena »

Thanks for sharing
Post Reply