Here is my entire script:
Code: Select all
::-- Set Working Directory as Script Path --::
cd /d %~dp0
::-- Call Environment File --::
CALL \\DIPRDHYPESS03W\F$\Hyperion_Batch\Scripts\Batch\_env.cmd
::-- Set Main Intrapath Variables --::
::-- Set Process in variables below i.e EPMA_Logs\
SET PLOGPATH=Update_Subvars_Logs\
SET PERRORPATH=Update_Subvars_Errors\
SET intrapath=%ESS_SERVER%\%MAINPATH_RMT%%LOGPATH%%PLOGPATH%
SET errorintrapath=%ESS_SERVER%\%MAINPATH_RMT%%ERRORPATH%%PERRORPATH%
IF NOT EXIST %intrapath% MKDIR %intrapath%
IF NOT EXIST %errorintrapath% MKDIR %errorintrapath%
::-- 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)
SET logfile=%intrapath%%date:~-4,4%%date:~-10,2%%date:~-7,2%_%timestamp%_%~n0.log
SET errorfile=%errorintrapath%%date:~-4,4%%date:~-10,2%%date:~-7,2%_%timestamp%_%~n0.log
::-- Prepare Log & Error file directories --::
FOR %%f IN ( %MAINPATH%%LOGPATH%%PLOGPATH%* ) DO ( DEL %%f )
FOR %%f IN ( %MAINPATH%%ERRORPATH%%PERRORPATH%* ) DO ( DEL %%f )
::-- Set Subvar Process Variables --::
SET FINDSTR=C:\Windows\System32\findstr.exe
SET SUBVAR_OUTPUT=%intrapath%Subvar_Output.txt
SET SUBVAR_PROC_PATH=%MAINPATH%%FILEPATH%Subvar_Maintenance\Update_Subvars.txt
IF EXIST %SUBVAR_PROC_PATH% DEL %SUBVAR_PROC_PATH%
echo ********************************************************>>%logfile%
echo %~n0 Starting at %TIME% >>%logfile%
echo ********************************************************>>%logfile%
echo ********************************************************>>%logfile%
echo Extract Valid Substition Variables for Month End >>%logfile%
echo ********************************************************>>%logfile%
::-- Extract subvars from Essbase --::
CALL %STARTESSMSHPATH%ESSMSH.EXE %ESS_SERVER%\%MAINPATH_RMT%%MAXLPATH%Extract_Subvarsnew.mxl %ESSB_USER% %ESSB_PSWD% %ESSB_SRVR% %ESSB_APP% %ESSB_DB% %SUBVAR_OUTPUT%
::-- Find Subvars extracted above, and return value and spool to file in import format --::
(FOR %%S IN (
CurMo
CurQtr
FMVFXMth
NextMo
NextMo2
NextQtr
NextQtr2
PemCM
PemNM
PreMo
PreMo2
PreQtr
CurYr
NextYr
NextYr2
NextYr3
NextYr4
NextYr5
PemCY
PemNY
PreYr
PreYr2
PreYr3
) DO (FOR /F "TOKENS=4" %%A IN ('"%FINDSTR%" "\<%%S\>" "%SUBVAR_OUTPUT%"'
) DO ECHO=%ESSB_APP%,%ESSB_DB%,%%S,%%A))>>"%SUBVAR_PROC_PATH%Updated_Subvars.txt"
SET myError1=%errorlevel%
IF %myError1%==0 goto NormalExit
echo **********************************************************************>>%logfile%
echo Encountered Error in Extract Valid Substition Variables for Month End >>%logfile%
echo **********************************************************************>>%logfile%
goto AbnormalExit
:NormalExit
echo ********************************************************>>%logfile%
echo %~n0 - Completed Successfully >>%logfile%
echo ********************************************************>>%logfile%
echo ********************************************************>>%logfile%
echo Normal Exit - %~nx0 >>%logfile%
echo ********************************************************>>%logfile%
date /t >>%logfile%
time /t >>%logfile%
CALL :ARCHIVE
EXIT /B 0
:AbnormalExit
echo ********************************************************>>%errorfile%
echo %~n0 - Completed Unsuccessfully >>%errorfile%
echo ********************************************************>>%errorfile%
echo Please Check the log file for errors >>%errorfile%
echo ********************************************************>>%errorfile%
echo Abnormal Exit - %~nx0 >>%errorfile%
echo ********************************************************>>%errorfile%
date /t >>%errorfile%
time /t >>%errorfile%
CALL :ARCHIVE
EXIT /B 1
:ARCHIVE
::-- Archive Log Files Based on Date --::
FOR %%f IN (%MAINPATH%%LOGPATH%%PLOGPATH%*) DO (
IF NOT EXIST "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\" (
MKDIR "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
MOVE "%%f" "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
::-- Archive Error Files Based on Date --::
FOR %%f IN (%MAINPATH%%ERRORPATH%%PERRORPATH%*) DO (
IF NOT EXIST "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\" (
MKDIR "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
MOVE "%%f" "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
GOTO :EOF
Here is what the Subvar_Output.txt file looks like:
Code: Select all
MAXL> login admin System11admin on DIPRDHYPESS03W;
OK/INFO - 1051034 - Logging in user [admin@Native Directory].
OK/INFO - 1241001 - Logged in to Essbase.
MAXL> display variable on database "DIFIN"."DIFIN";
application database variable value
+-------------------+-------------------+-------------------+-------------------
DIFIN DIFIN PtrRM Jan
DIFIN DIFIN ThisYear FY06
DIFIN DIFIN BudYr FY16
DIFIN DIFIN CurYr FY16
DIFIN DIFIN NexYr FY17
DIFIN DIFIN NexYr2 FY18
DIFIN DIFIN NexYr3 FY19
DIFIN DIFIN NexYr4 FY20
DIFIN DIFIN NexYr5 FY21
DIFIN DIFIN PemBY FY15
DIFIN DIFIN PemCY FY16
DIFIN DIFIN PemNY FY17
DIFIN DIFIN PreYr FY15
DIFIN DIFIN PreYr2 FY14
DIFIN DIFIN PreYr3 FY13
DIFIN DIFIN PtrCY FY16
DIFIN DIFIN PtrNY FY17
DIFIN DIFIN PtrNY2 FY18
DIFIN DIFIN PtrNY3 FY19
DIFIN DIFIN PtrNY4 FY20
DIFIN DIFIN PtrNY5 FY21
DIFIN DIFIN PtrPY FY15
DIFIN DIFIN NexQtr2 Q4
DIFIN DIFIN NexQtr Q4
DIFIN DIFIN CurQtr Q3
DIFIN DIFIN FMVFXMth Dec
DIFIN DIFIN PreQtr Q2
DIFIN DIFIN PtrCM Sep
DIFIN DIFIN PtrNM2 Nov
DIFIN DIFIN PtrNM Oct
DIFIN DIFIN CurMo Oct
DIFIN DIFIN NexMo Nov
DIFIN DIFIN NexMo2 Dec
DIFIN DIFIN PemCM Oct
DIFIN DIFIN PemNM Nov
DIFIN DIFIN PreMo Sep
DIFIN DIFIN PreMo2 Aug
WARNING - 1241024 - Possible string truncation in column 3.
WARNING - 1241028 - Output column defined with warnings.
WARNING - 1241024 - Possible string truncation in column 4.
WARNING - 1241028 - Output column defined with warnings.
OK/INFO - 1241044 - Records returned: [37].
MAXL> logout;
User admin is logged out
Since I archive the log and error files at the end, My intention is to make sure tose two directories are clean prior to executing again. I will also be adding another error catching portion above your code you provided.