Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tbharber
- Posts: 32
- Joined: 17 Sep 2010 17:08
#1
Post
by tbharber » 26 May 2013 20:11
I have the following script which checks for multiple running services on remote servers...
Code: Select all
set server1=scrfaxp5
set server2=scrfaxp6
set server3=scrfaxp8
set server4=srrfaxp5
set server5=srrfaxp6
set server6=srrfaxp8
echo "Verifying services..."
echo.
echo "%server1%"
echo "RightFax Database Module" & sc \\%server1% query RFDB|findstr STATE & echo.
echo "RightFax DocTransport Module" & sc \\%server1% query RFDOCTRANS|findstr STATE & echo.
echo "RightFax E-mail Gateway Module" & sc \\%server1% query RFEMAIL|findstr STATE & echo.
echo "RightFax eTransport Module" & sc \\%server1% query RFMIME|findstr STATE & echo.
echo "RightFax Paging Server Module" & sc \\%server1% query RFPAGE|findstr STATE & echo.
echo "RightFax Integration Module" & sc \\%server1% query RFPROD|findstr STATE & echo.
echo "RightFax Queue Handler" & sc \\%server1% query RFQUEUE|findstr STATE & echo.
echo "RightFax Remoting Service" & sc \\%server1% query RFRemote|findstr STATE & echo.
echo "RightFax RPC Server Module" & sc \\%server1% query RFRPC|findstr STATE & echo.
echo "RightFax Server Module" & sc \\%server1% query RFSERVER|findstr STATE & echo.
echo "RightFax WorkServer1 Module" & sc \\%server1% query RFWORK1|findstr STATE & echo.
echo "RightFax WorkServer2 Module" & sc \\%server1% query RFWORK2|findstr STATE & echo.
echo "RightFax WorkServer3 Module" & sc \\%server1% query RFWORK3|findstr STATE & echo.
echo "RightFax WorkServer4 Module" & sc \\%server1% query RFWORK4|findstr STATE & echo.
echo "RightFax WorkServer5 Module" & sc \\%server1% query RFWORK5|findstr STATE & echo.
echo "Captaris Conversion Engine" & sc \\%server1% query RFIsoConv|findstr STATE & echo.
echo "Captaris Sync Module" & sc \\%server1% query CapaSync|findstr STATE & echo.
What I need is to do a loop at the end and run the same code for %server2% and then %server3%, and so on though all 6 server variables. I have tried to do a loop by adding 1 to the end of the variable but it will not work.
Any ideas???
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#2
Post
by Endoro » 26 May 2013 23:23
tbharber wrote:Any ideas???
try this:
Code: Select all
@echo off&setlocal
for %%i in (
scrfaxp5
scrfaxp6
scrfaxp8
srrfaxp5
srrfaxp6
srrfaxp8
) do (
echo "Verifying services..."
echo.
echo "%%i"
echo "RightFax Database Module" & sc \\%%i query RFDB|findstr STATE & echo.
echo "RightFax DocTransport Module" & sc \\%%i query RFDOCTRANS|findstr STATE & echo.
echo "RightFax E-mail Gateway Module" & sc \\%%i query RFEMAIL|findstr STATE & echo.
echo "RightFax eTransport Module" & sc \\%%i query RFMIME|findstr STATE & echo.
echo "RightFax Paging Server Module" & sc \\%%i query RFPAGE|findstr STATE & echo.
echo "RightFax Integration Module" & sc \\%%i query RFPROD|findstr STATE & echo.
echo "RightFax Queue Handler" & sc \\%%i query RFQUEUE|findstr STATE & echo.
echo "RightFax Remoting Service" & sc \\%%i query RFRemote|findstr STATE & echo.
echo "RightFax RPC Server Module" & sc \\%%i query RFRPC|findstr STATE & echo.
echo "RightFax Server Module" & sc \\%%i query RFSERVER|findstr STATE & echo.
echo "RightFax WorkServer1 Module" & sc \\%%i query RFWORK1|findstr STATE & echo.
echo "RightFax WorkServer2 Module" & sc \\%%i query RFWORK2|findstr STATE & echo.
echo "RightFax WorkServer3 Module" & sc \\%%i query RFWORK3|findstr STATE & echo.
echo "RightFax WorkServer4 Module" & sc \\%%i query RFWORK4|findstr STATE & echo.
echo "RightFax WorkServer5 Module" & sc \\%%i query RFWORK5|findstr STATE & echo.
echo "Captaris Conversion Engine" & sc \\%%i query RFIsoConv|findstr STATE & echo.
echo "Captaris Sync Module" & sc \\%%i query CapaSync|findstr STATE & echo.
)
and this does also work:
Code: Select all
@echo off&setlocal
set /a maxserver=6
set "server1=scrfaxp5"
set "server2=scrfaxp6"
set "server3=scrfaxp8"
set "server4=srrfaxp5"
set "server5=srrfaxp6"
set "server6=srrfaxp8"
for /l %%i in (1,1,%maxserver%) do (
setlocal enabledelayedexpansion
echo "Verifying services..."
echo.
echo "!server%%i!"
echo "RightFax Database Module" & sc \\!server%%i! query RFDB|findstr STATE & echo.
echo "RightFax DocTransport Module" & sc \\!server%%i! query RFDOCTRANS|findstr STATE & echo.
echo "RightFax E-mail Gateway Module" & sc \\!server%%i! query RFEMAIL|findstr STATE & echo.
echo "RightFax eTransport Module" & sc \\!server%%i! query RFMIME|findstr STATE & echo.
echo "RightFax Paging Server Module" & sc \\!server%%i! query RFPAGE|findstr STATE & echo.
echo "RightFax Integration Module" & sc \\!server%%i! query RFPROD|findstr STATE & echo.
echo "RightFax Queue Handler" & sc \\!server%%i! query RFQUEUE|findstr STATE & echo.
echo "RightFax Remoting Service" & sc \\!server%%i! query RFRemote|findstr STATE & echo.
echo "RightFax RPC Server Module" & sc \\!server%%i! query RFRPC|findstr STATE & echo.
echo "RightFax Server Module" & sc \\!server%%i! query RFSERVER|findstr STATE & echo.
echo "RightFax WorkServer1 Module" & sc \\!server%%i! query RFWORK1|findstr STATE & echo.
echo "RightFax WorkServer2 Module" & sc \\!server%%i! query RFWORK2|findstr STATE & echo.
echo "RightFax WorkServer3 Module" & sc \\!server%%i! query RFWORK3|findstr STATE & echo.
echo "RightFax WorkServer4 Module" & sc \\!server%%i! query RFWORK4|findstr STATE & echo.
echo "RightFax WorkServer5 Module" & sc \\!server%%i! query RFWORK5|findstr STATE & echo.
echo "Captaris Conversion Engine" & sc \\!server%%i! query RFIsoConv|findstr STATE & echo.
echo "Captaris Sync Module" & sc \\!server%%i! query CapaSync|findstr STATE & echo.
endlocal
)