Vote count:
0
This is my code using to run batch script to run SQL script and generating execution log. Help me to understand ::Echo off will hide all commands written in text file @echo off
:: Declaring colour appearance of the batch
color Af
setlocal enabledelayedexpansion
::Declaration of the SQL Server Name.
set servername=192.168.90.34
:: Declaration of the source path where we will keep script file.
set spath=D:\Batch_Test_File\Script_File
::Declaration of the destination Path where we will move script file after successful execution.
set dpath=D:\Batch_Test_File\Executed_script\Enterprise_Script
:: Creation of the Execution log folder basis of current date.
set TIMESTAMP=%DATE:~7,2%%DATE:~4,2%%DATE:~10,4%
IF EXIST "%D:\Batch_Test_File\Execution_log\%TIMESTAMP%" (
echo Folder exist
set lpath=D:\Batch_Test_File\Execution_log\%TIMESTAMP%
echo %lpath%
) ELSE (
md "%D:\Batch_Test_File\Execution_log\%TIMESTAMP%"
set lpath=D:\Batch_Test_File\Execution_log\%TIMESTAMP%
echo %lpath%
)
:: Declaration of the credential of the SQL Server 2008
set uname=sa
set pwd=sa@gr8
:: Defining Flag for capturing error status of script file
set temp=0
echo temp value1:-%temp%
:: Printing ServerName on Which script will apply.
echo Server_Name:-%servername%
:: Printing Source path of the script file
echo File_Path:-%spath%
pause
:: Listing all files from Source Path
set cmd='dir %spath%\*ED*.sql /b/s'
echo %cmd%
pause
::Creating Log file basis of script file available
::Taken a loop as per the count of file in CMD Variable
FOR /f "delims=" %%G IN (%cmd%) DO (
echo inside loop
set _fn=%%G
set _fn=!_fn:~31,11!
set logfilepath= %lpath%\output_!_fn!.log
echo %logfilepath%--Here echo is off coming. If Using echo !logfilepath! then it is printing but not able to capture log further
echo logfilepath1 file name here
pause
FOR /F "tokens=*" %%A in (D:\Batch_Test_File\EnterpriseDatabaseList.txt) do (
echo Database_Name:- %%A >> %logfilepath%---here throwing syntax error
echo ******PROCESSING %%G FILE******
SQLCMD -S%servername% -U %uname% -P %pwd% -d %%A -b -i%%G >> %logfilepath%
echo %%G File
echo Database_Name:- %%A >> %logfilepath%
IF !ERRORLEVEL! EQU 0 echo ******PROCESSED %%G FILE****** >> %logfilepath%
IF !ERRORLEVEL! NEQ 0 echo ******NOT PROCESSED %%G FILE****** >> %logfilepath%
IF !ERRORLEVEL! NEQ 0 set /a temp+=1
echo SQL SERVER ERROR:- !ERRORLEVEL!
)
MOVE %%G %dpath%
)
::pause echo temp value2:-%temp% pause IF %temp% EQU 0 GOTO Success IF NOT GOTO :OnError
:OnError echo ERROR ERROR ERROR echo One\more script(s) failed to execute, terminating path. echo Check output.log file for more details echo File not moved >> %logfilepath% pause EXIT /b
:Success echo ALL the scripts deployed successfully!! >> %logfilepath% pause EXIT /b
Please help me on this!
asked 24 secs ago
Why echo Off and syntax error is there for my code
Aucun commentaire:
Enregistrer un commentaire