Weird behavoir between servers - same script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Weird behavoir between servers - same script

#1 Post by SIMMS7400 » 14 Dec 2017 05:34

Hi Folks -

I have a utility script that I build that is able to stop,start,restart services as well as stop, start, restart and ping any server. The paramaters are obviously passed in dynamically from the calling script.

The issue is, I have a peice of code that extracts the status of each service. In one environment, the process works flawlessly - no issues. But on my production box, this particular line of code fails, claiming \\<system name> is unexpected at this time:

Code: Select all

::-- Parse output of command and set STATE as a variable for script processing --::
FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%" ^| FIND "STATE"') DO SET "CURRENT_STATUS=%%S"
The variables in that command line are as follows:

Code: Select all

SET PSUser=Domain\srvc-hypadmin
SET PSPass=J72Dppsssas)
SET PSSERVICE=C:\ESSBASE_BATCH\Utilities\PSTools\PsService.exe -u %PSUser% -p %PSPass%

And then the system and services are passed in as such:

::-- Set Servers --::

SET "FND_SRVR=10.51.2.70"
SET "ESSB_SRVR=10.51.2.71"

echo ********************************************************
echo %ACTION% EPM Services on %FND_SRVR%             		   	     
echo ********************************************************

FOR %%S IN ( 
 
 "HyS9eas_epmsystem1"
 "HyS9CALC_epmsystem1"
 "HyS9EPMADataSynchronizer_epmsystem1"
 "HyS9EPMAServer_epmsystem1"
 "HyS9EPMAWebTier_epmsystem1"
 "HyS9FRReports_epmsystem1"
 "HyS9FoundationServices_epmsystem1"
 "HyS9Planning_epmsystem1"
 "HyS9RaFramework_epmsystem1"
 "HyS9RaFrameworkAgent_epmsystem1"
 "HyS9RMIRegistry_epmsystem1"
 "OracleProcessManager_ohsInstance3250625901" ) DO (

	CALL SafeStopStartRestart.cmd "%ACTION%" "%%~S" "%FND_SRVR%" "%PLOGPATH%" "%PERRORPATH%"

)
I can't seem to understand why the script is having trouble on one server but not the other. Security is fine, I even ran as admin with no avail. Any ideas?

Thanks!

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

Re: Weird behavoir between servers - same script

#2 Post by aGerman » 14 Dec 2017 06:33

Most likely something that produces additional tokens like spaces, commas, ampersands, etc. Also think about characters that get removed if they were passed using call like percent signs.

Steffen

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

Re: Weird behavoir between servers - same script

#3 Post by SIMMS7400 » 14 Dec 2017 08:30

Steffen -

I thought the same as well, but the only difference between servers is the server IP obviously - the scripts are identical as are the services being passed in.

Also if the take the command out of the for loop execute it like such it works fine:

Code: Select all

%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%"


Ill keep digging.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Weird behavoir between servers - same script

#4 Post by Squashman » 14 Dec 2017 09:08

You have a right parentheses in your password.

I don't see where the systemname variable is defined.

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

Re: Weird behavoir between servers - same script

#5 Post by SIMMS7400 » 14 Dec 2017 09:12

Here is my utility script:

Code: Select all

::-- Set Working Directory as Script Path --::

CD /D "%~dp0"

::-- Call Environment File --::

CALL _env.cmd

::-- Set Main INTRAPATH Variables --::

SET "PLOGPATH=%~4"
SET "PERRORPATH=%~5"

SET "INTRAPATH=%MAINPATH%%LOGPATH%%PLOGPATH%"
SET "ERRORINTRAPATH=%MAINPATH%%ERRORPATH%%PERRORPATH%"

::-- Prepare Main Log and Error Files  --::

FOR /f "tokens=1-2 delims=/:" %%A IN ("%TIME%") DO ( SET "TIMESTAMP=%%A%%B" )
FOR /f "tokens=* delims= " %%C IN ("%TIMESTAMP%") DO ( SET "TIMESTAMP=%%C" )

::-- Construct Log ^& Error file name based on action --::

IF "%~1"=="RESTART_SERVER" (
	SET "LOGFILE=%INTRAPATH%%~1_%~3_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.log"
	SET "ERRORFILE=%ERRORINTRAPATH%%~1_%~3_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.err"
	) ELSE IF "%~1"=="PING" (
		SET "LOGFILE=%INTRAPATH%%~1_%~3_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.log"
		SET "ERRORFILE=%ERRORINTRAPATH%%~1_%~3_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.err"
	) ELSE (
		SET "LOGFILE=%INTRAPATH%%~1_%~2_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.log"
		SET "ERRORFILE=%ERRORINTRAPATH%%~1_%~2_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%TIMESTAMP%.err"
)

::-- Call function to pass in ACTION ^| SERVICE ^| SERVER --::

CALL :EXEC_ACTION "%~1" "%~2" "%~3"

::-- Return to main script to process more commands or exit session --::
CLS
EXIT /B 0

:EndExit
>>"%LOGFILE: =_%" (
ECHO ************************************************************************
ECHO MESSAGE :
ECHO. 
ECHO Server "\\%SYSTEMNAME%" has completed processing
ECHO No further action required - exiting session          
ECHO ------------------------------------------------------------------------                                                                     
ECHO.
)
GOTO :EOF

::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  V A R I A B L E   D E C L A R A T I O N   --::
::::::::::::::::::::::::::::::::::::::::::::::::::::

:EXEC_ACTION

::-- Ensure command line argument exist before processing --::
	::-- %1 will always be ACTION --::
	::-- %2 will always be SERVICE --::
	::-- %3 will always be SERVER --::
	::-- %4 is normally log file sub directory ^[i.e. "DRM_Services_Logs\" ^] --::
		::-- This parameter is not required --::
	::-- %5 is normally error file sub directory ^[i.e. "DRM_Services_Errors\" ^] --::
		::-- This parameter is not required --::		

IF ["%~1"] == [""] GOTO Usage
IF ["%~2"] == [""] GOTO Usage
IF ["%~3"] == [""] GOTO Usage

::-- Set command line arguements to a variable for easier reading --::
::-- Perform variable transformation --::

SET "ACTION=%~1"
SET "SERVICENAME=%~2"
SET "SYSTEMNAME=%~3"

::-- Reset Main Routine Variables --::

SET "STATE="
SET "CURRENT_STATUS="
SET "FLAG="

::-- SET /A used so variable can be evaluated with a number rather than string value --::

SET /A "DEFAULT_DELAY=10"
SET /A "SLEEP_COUNT=0"
SET /A "RESTARTED=0"
SET /A "MAX_WAIT_PERIODS=5"
SET /A "PING_CNT=0"

::-- Set Ping Delay based on Action --::
IF "%~1"=="STOP" ( 
	SET /A "PING_DELAY=5"
) ELSE IF "%~1"=="START" (
	SET /A "PING_DELAY=10"
) ELSE IF "%~1"=="RESTART_SERVER" (
	SET /A "PING_DELAY"="0"
) ELSE IF "%~1"=="PING" (
	SET /A "PING_DELAY"="0"
) ELSE (
	SET /A "PING_DELAY"="5"
)

::-- If server related, Set SERVICENAME to null --::
	::-- Set FLAG==T so only server related code is executed against --:

IF "%~1"=="RESTART_SERVER" (
	SET "SERVICENAME="
	SET "FLAG=T"
) ELSE IF "%~1"=="PING" (
	SET "SERVICENAME="
	SET "FLAG=T"
)
	
::-- Set IP Address --::

FOR /f "delims=[] tokens=2" %%A IN ('PING %SYSTEMNAME% -n 1 ^| FINDSTR "["') DO SET "IP=%%A"

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  B E G I N   M A I N   S C R I P T   P R O C E S S I N G  --::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::-- Display content to CLI for display during ad-hoc executions --::
	::-- SERVICENAME quotes are removed for display --::

CLS
ECHO ************************************************************************ 
ECHO Process Info  : %TIME%                                                          
ECHO ------------------------------------------------------------------------                                                                
ECHO Server Name   ^: %SYSTEMNAME%
ECHO IP Address    ^: %IP%
ECHO.                                              
ECHO Action        ^: %ACTION%                                                  
ECHO Service Name  ^: %SERVICENAME%                                   
ECHO.

IF NOT DEFINED FLAG (
	ECHO Attempting to %ACTION% service "%SERVICENAME%"
)	ELSE (                                                                        
		ECHO Attempting to %ACTION% ^: %SYSTEMNAME%
	)	
ECHO ------------------------------------------------------------------------ 

>>"%LOGFILE: =_%" (
ECHO ************************************************************************  
ECHO Process Info  ^: %TIME%                                                    
ECHO ------------------------------------------------------------------------                                                                  
ECHO Server Name   ^: %SYSTEMNAME%                                              
ECHO IP Address    ^: %IP%													  
ECHO.                                                                         
ECHO Action        ^: %ACTION%                                                  
ECHO Service Name  ^: %SERVICENAME%                                          
ECHO.                                                                          

IF NOT DEFINED FLAG (
	ECHO Attempting to %ACTION% service "%SERVICENAME%"
)	ELSE (                                                                        
		ECHO Attempting to %ACTION% ^: %SYSTEMNAME%
	)	
ECHO ------------------------------------------------------------------------ 
)

PING -n %PING_DELAY% 127.0.0.1>nul

::-- The code from this point to :SRVC label pertains only to Server actions ^[i.e PING ^| RESTART_SERVER^] --::
IF NOT DEFINED FLAG GOTO SRVC

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  B E G I N    S E R V E R    R E L A T E D   A C T I O N S    O N L Y    --::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::-- Ensure Server is valid, accessiable, and not offline --::
	::--  If network is IPv6, -4 resolves to IPv4 format --::
	::--  IPv6 does not resolve to normal IP Address string --::

PING -n 1 -4 %SYSTEMNAME% | FIND /i "TTL=" >nul 2>&1

IF "%ERRORLEVEL%"=="0" (
	>>"%LOGFILE: =_%" (
	ECHO.    												       
	ECHO Server %SYSTEMNAME% is valid and available for processing 
	ECHO.													     
	)
	GOTO RestartServer
)

:P2
PING -n 1 -4 %SYSTEMNAME% | FIND /i "Destination host unreachable" >nul 2>&1

IF "%ERRORLEVEL%"=="0" (
	IF "%PING_CNT%"=="0" (
		>>"%LOGFILE: =_%" (
		ECHO.    												                  
		ECHO %SYSTEMNAME% is unreachable ^: No valid route to the requested host   
		ECHO.
		SET /A RETRY_CNT=%MAX_WAIT_PERIODS%-%PING_CNT%
		ECHO Will try to contact host %RETRY_CNT% more times               
		ECHO. 													                 
		)
	)
	IF "%PING_CNT%"=="%MAX_WAIT_PERIODS%" (
		>>"%LOGFILE: =_%" (
		ECHO.                                                                     
		ECHO Error : %SYSTEMNAME% state will not change                        
		ECHO.                                                                  
		ECHO No further attempts will be made                                 
		ECHO.                                                                     
		)
		GOTO EndExit
	)
PING -n %DEFAULT_DELAY% 127.0.0.1>nul
SET /A "PING_CNT+=1"
GOTO P2
)

:P3
PING -n 1 -4 %SYSTEMNAME% | FIND /i "Request timed out" >nul 2>&1

IF "%ERRORLEVEL%"=="0" (
	IF "%PING_CNT%"=="0" (
		>>"%LOGFILE: =_%" (
		ECHO.    												                     
		ECHO The request to %SYSTEMNAME% has timed out                               
		ECHO. 													                     
		ECHO No ECHO reply messages were recieved within the default time of 1 second
		ECHO.
		SET /A RETRY_CNT=%MAX_WAIT_PERIODS%-%PING_CNT%
		ECHO Will try to contact host %RETRY_CNT% more times                  
		ECHO.													                     
		)
	)
	IF "%PING_CNT%"=="%MAX_WAIT_PERIODS%" (
		>>"%LOGFILE: =_%" (
		ECHO.                                                                      
		ECHO Error : %SYSTEMNAME% state will not change                         
		ECHO.                                                                     
		ECHO No further attempts will be made                                     
		ECHO.                                                                     
		)
		GOTO EndExit
	)
PING -n %DEFAULT_DELAY% 127.0.0.1>nul
SET /A "PING_CNT+=1"
GOTO P3
)

PING -n 1 -4 %SYSTEMNAME% | FIND /i "could not find host">nul 2>&1

IF "%ERRORLEVEL%"=="0" (
	>>"%LOGFILE: =_%" (
	ECHO.    												         
	ECHO Error : %SYSTEMNAME% is not valid                         
	ECHO. 													        	
	ECHO No further attempts will be made                          
	ECHO. 													        
	)
	GOTO EndExit
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  E N D    S E R V E R    R E L A T E D   A C T I O N S    O N L Y    --::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  B E G I N    S E R V I C E    R E L A T E D   A C T I O N S    O N L Y    --::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::-- Ensure Server is valid, accessiable, and not offline --::

:SRVC

%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%" | FIND "FAILED 1060" >nul 2>&1
IF "%ERRORLEVEL%"=="0" (
	>>"%LOGFILE: =_%" (
    ECHO.                                             
    ECHO Error! Service "%SERVICENAME%" is not valid! 
	ECHO.                                             
	)
    GOTO EndExit
)

%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%" | FIND "STATE" >nul 2>&1

IF "%ERRORLEVEL%"=="1" (
	>>"%LOGFILE: =_%" (
    ECHO.                                                                               
    ECHO Error! Server \\%SYSTEMNAME% or service "%SERVICENAME%" is not accessible or is offline! 
	ECHO.                                                                               
	)
    GOTO EndExit
)

:Dispatch

::-- Parse output of command and set STATE as a variable for script processing --::
FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%" ^| FIND "STATE"') DO SET "CURRENT_STATUS=%%S"

>>"%LOGFILE: =_%" (
ECHO.
ECHO Current State : Service is %CURRENT_STATUS%
)

::-- Perform required checks and balances after service has been stopped or started --::
IF NOT "%CURRENT_STATUS%"=="RUNNING" IF NOT "%CURRENT_STATUS%"=="STOPPED" IF NOT "%CURRENT_STATUS%"=="PAUSED" (
    IF "%SLEEP_COUNT%"=="%MAX_WAIT_PERIODS%" (
		>>"%LOGFILE: =_%" (
	    ECHO.                                                           
        ECHO Error - "%SERVICENAME%" state will not change
		ECHO Script exececution is canceled
		ECHO.                                                           
		)
        GOTO EndExit
    )
>>"%LOGFILE: =_%" (
ECHO.                                                              
ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...  
ECHO.                                                              
)
PING -n %DEFAULT_DELAY% 127.0.0.1>nul
SET /A "SLEEP_COUNT+=1"
GOTO Dispatch
)

IF "%ACTION%"=="START" (
    IF "%CURRENT_STATUS%"=="RUNNING" (
		>>"%LOGFILE: =_%" (
        ECHO.                                          
        ECHO Warning! Service %SERVICENAME% is running 
		ECHO.                                          
        ECHO No further processing required            
        ECHO.                                         
		)
		GOTO EndExit
    ) ELSE (
        GOTO StartService
    )
) ELSE IF "%ACTION%"=="RESTART" (
    IF "%CURRENT_STATUS%"=="RUNNING" (
        IF "%RESTARTED%"=="1" (
			>>"%LOGFILE: =_%" (
			ECHO.                                                           
			ECHO Warning! Service "%SERVICENAME%" has already been restarted  
			ECHO.                                                          
            ECHO No further processing required                            
			ECHO.                                                          
			)
            GOTO EndExit
        )
        SET /A "SLEEP_COUNT=0"
        GOTO StopService
    ) ELSE (
        SET /A "RESTARTED=1"
        GOTO StartService
    )
) ELSE IF "%ACTION%"=="STOP" (
    IF "%CURRENT_STATUS%"=="STOPPED"  (
		>>"%LOGFILE: =_%" (
		ECHO.                                                 
        ECHO Warning! Service "%SERVICENAME%" has been stopped. 
		ECHO.                                                 
		ECHO No further processing required                   
		ECHO.                                                
		)
        GOTO EndExit
    ) ELSE (
        GOTO StopService
    )
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--  E N D    S E R V I C E    R E L A T E D   A C T I O N S    O N L Y    --::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:StartService

::-- If start fails, the service was incorrectly set above or an erratic status was detected --::
	::-- The service has a status of STOPPED and an action of START --::
	::-- But PsService attempted to start it, execution fails because it is already started --::
	::-- Identify why service is not assuming the correct status --::
	
>>"%LOGFILE: =_%" (
ECHO.                                         		       
ECHO Currently starting "%SERVICENAME%"
ECHO.                                         		      
)
FOR /f "tokens=1-5" %%A IN (
	'%PSSERVICE% \\%SYSTEMNAME% start "%SERVICENAME%" ^| FIND "Error"'
	) DO SET "ECHK=%%B" & "SET CMDOP=%%A %%B %%C %%D %%E"

>>"%LOGFILE: =_%" (
IF "%ECHK%"=="starting" (
	
	ECHO Warning! A service conflicts exists:     		 
	ECHO.                                         		 
	ECHO Error Message: %CMDOP%							 
	ECHO.                                         		 
	ECHO %~2 was labeled as %CURRENT_STATUS%     		 
	ECHO Process action was to %ACTION% the service      
	ECHO PsService FAILED as it was already started      
	ECHO.                                         		 
	ECHO Please understand the incorrect status setting	 
	ECHO.                                         		 
	GOTO EndExit
)

IF "%ECHK%"=="opening" (

	ECHO Warning! A service conflicts exists:                   	 
	ECHO.                                               	    	 
	ECHO Error Message: %CMDOP%						    	     
	ECHO.                                         	    	     
	ECHO This error could mean the  following:                  
	ECHO.													    
	ECHO 1. Access is Denied : User unable to access service    
	ECHO 2. The service does exist as an installed service         
	ECHO.                                            		    
	ECHO Run process as Administrator or check service validity	
	ECHO.														
	GOTO EndExit
)
	
IF "%ECHK%"=="controlling" (

	ECHO Warning! A service conflicts exists:     		             
	ECHO.                                         		             
	ECHO Error Message: %CMDOP%							             
	ECHO.                                         		             
	ECHO The current process cannot control the service              
	ECHO.                                         		             
	ECHO %~2 was labeled as %CURRENT_STATUS%     		             
	ECHO Process action was to %ACTION% the service                  
	ECHO PsService FAILED as it could not ascertain a STOPPED status 
	ECHO.                                         	                 
	ECHO Please verify the service status           	             
	ECHO.                                         		             
	GOTO EndExit
) 
	
ECHO Verifying service has been started...
ECHO.                                     
SET "SLEEP_COUNT=0"
)
GOTO Dispatch
	
:StopService

>>"%LOGFILE: =_%" (
ECHO.                                                      
ECHO Currently stopping "%SERVICENAME%"
ECHO.                                                     
)

FOR /f "tokens=1-5" %%A IN (
	'%PSSERVICE% \\%SYSTEMNAME% stop "%SERVICENAME%" ^| FIND "Error"'
	) DO SET "ECHK=%%B" & SET "CMDOP=%%A %%B %%C %%D %%E"

>>"%LOGFILE: =_%" (
IF "%ECHK%"=="opening" (

	ECHO Warning! A service conflicts exists:                    
	ECHO.                                               	     
	ECHO Error Message: %CMDOP%						    	     
	ECHO.                                         	    	     
	ECHO This error could mean the  following:                  
	ECHO.													    
	ECHO 1. Access is Denied : User unable to access service    
	ECHO 2. The service does exist as an installed service         
	ECHO.                                            		    
	ECHO Run process as Administrator or check service validity	
	ECHO.														
	GOTO EndExit
	)
	
IF NOT DEFINED ECHK (

	ECHO Warning! A service conflicts exists:     		             
	ECHO.                                         		             
	ECHO Error Message: %CMDOP%							             
	ECHO.                                         		             
	ECHO The current process cannot control the service              
	ECHO.                                         		             
	ECHO %~2 was labeled as %CURRENT_STATUS%     		             
	ECHO Process action was to %ACTION% the service                  
	ECHO PsService FAILED as it could not ascertain a RUNNING status 
	ECHO.                                         	                 
	ECHO Please verify the service status           	             
	ECHO.                                         		             
	GOTO EndExit
) 
	
ECHO Verifying service has been stopped...
ECHO.                                     
SET "SLEEP_COUNT=0"
)
GOTO Dispatch

:RestartServer

::-- If restart failed, the issue is most likely due to access --::
	::-- The current process would have made it this far if server was unavailable --::
	::-- Contact your System Administrator --::
	
IF "%~1"=="PING" GOTO EndExit	

ECHO Restarting \\%SYSTEMNAME%... >>"%LOGFILE: =_%"
CALL %PSSHUTDOWN% \\%SYSTEMNAME% -f -r -t 60 -m "\\%SYSTEMNAME% : Restarting in 1 minute - please save your work and log out" ||GOTO FAILED

>>"%LOGFILE: =_%" (
ECHO.                                                                               
ECHO "%SYSTEMNAME%" is being restarted : 
ECHO Allow 5 minutes to complete before accessing
ECHO.                                                                              
)
GOTO EndExit

:FAILED
>>"%LOGFILE: =_%" (
ECHO.                                         		         
ECHO Warning! Access is denied : Server can not be restarted 
ECHO.                                         		         
ECHO Contact your System Administrator   		            
ECHO.                                                        
)
GOTO EndExit	


:Usage

ECHO.
ECHO Warning! Script processing has been aborted...
ECHO.
ECHO One or more of the ^(3^) required parameters has been supplied incorrectly.
ECHO.
ECHO Usage Example:
ECHO.
ECHO SafeStopStartRestart.cmd "START" "Oracle DRM Server Processes" "hyper-util-prd.corp.mpi.com" "DRM_Services_Logs\" "DRM_Services_Errors\"
ECHO.
ECHO Please note : the 4th and 5th parameters are NOT required
ECHO.
ECHO This script can performing the following actions^:
ECHO.
ECHO [1] STOP EPM Services
ECHO [2] START EPM Services
ECHO [3] RESTART EPM Services
ECHO [4] RESTART Windows Servers
ECHO [5] PING Windows Servers
ECHO.
ECHO ********************************************************

>>"%LOGFILE: =_%" (
ECHO.
ECHO Warning! Script processing has been aborted...
ECHO.
ECHO One or more of the ^(3^) required parameters has been supplied incorrectly.
ECHO.
ECHO Usage Example:
ECHO.
ECHO SafeStopStartRestart.cmd "START" "Oracle DRM Server Processes" "hyper-util-prd.corp.mpi.com" "DRM_Services_Logs\" "DRM_Services_Errors\"
ECHO.
ECHO Please note : the 4th and 5th parameters are NOT required
ECHO.
ECHO This script can performing the following actions^:
ECHO.
ECHO [1] STOP EPM Services
ECHO [2] START EPM Services
ECHO [3] RESTART EPM Services
ECHO [4] RESTART Windows Servers
ECHO [5] PING Windows Servers
ECHO.
ECHO ********************************************************
)
ECHO ^[Session will terminate in 30 seconds...^]
ECHO ********************************************************
PING -n 30 127.0.0.1>nul
GOTO EndExit

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Weird behavoir between servers - same script

#6 Post by Squashman » 14 Dec 2017 09:26

Well I guess you don't understand that parentheses are special characters and need to be escaped. Essentially your for command is expanding to this.

Code: Select all

FOR /f "tokens=4" %S IN ('C:\ESSBASE_BATCH\Utilities\PSTools\PsService.exe -u Domain\srvc-hypadmin -p J72Dppsssas) \\Server1 query "service" ^| FIND "STATE"') DO SET "CURRENT_STATUS=%S"
Do you see the problem now?

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

Re: Weird behavoir between servers - same script

#7 Post by SIMMS7400 » 14 Dec 2017 10:51

Oh my, changing:

Code: Select all

FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%SYSTEMNAME% query "%SERVICENAME%" ^| FIND "STATE"') DO SET "CURRENT_STATUS=%%S"
to this:

Code: Select all

FOR /f "tokens=4" %%S IN ('%PSSERVICE:)=^)% \\%SYSTEMNAME% query "%SERVICENAME%" ^| FIND "STATE"') DO SET "CURRENT_STATUS=%%S"
works!

Wow - still not sure why this only "broke" as I had had this same setup for month now and it worked...hmmmm.

Thank you, Squash!!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Weird behavoir between servers - same script

#8 Post by Squashman » 14 Dec 2017 11:18

Best practice in my humble opinion. You seem to quote your SET statement sometimes but not always.

Code: Select all

@echo off
SET "PSUser=Domain\srvc-hypadmin"
SET "PSPass=J72Dppsssas^)"
SET "PSSERVICE=C:\ESSBASE_BATCH\Utilities\PSTools\PsService.exe -u %PSUser% -p %PSPass%"

Post Reply