사용자가 최근 환경을 새로 고치고 변경 사항을 지우는 경우 약간의 코드를 환경에 재배포하는 데 사용할 수있는 간단한 배치 스크립트를 작성하려고합니다.Windows 배치 파일을 통해 실행할 때 ECHO가 올바르게 작동하지 않습니다.
스크립트는 훌륭하게 작동하지만 원하는대로 로깅하지 않습니다. 배포 과정에서 제한 사항을 수행합니다 (저는 DBA가 아니며 단지 개발자). ECHO 명령을 파일에 포함 할 수 없습니다.
배치 스크립트의 일부로이 문제를 해결하려면 작업 디렉토리에 "SET ECHO ON"및 "SPOOL file.log APPEND"명령이 포함 된 login.sql 파일을 만듭니다. 목표는 스크립트 전에 실행되어 내 결과를 스풀링한다는 것입니다. 그러나 SPOOL 명령이 작동하는 것처럼 보이지만 스크립트의 내용은 ECHO되지 않습니다. 이 모든 별도의 스크립트와 별도의 SQL * Plus 세션을 시작하기 때문에
는:: Identify all files that begin with a number and end with .sql and write to a file.
dir /b *.sql | findstr /b "[0-9]" > ScriptsToImplement.txt
:: Show the user the files to be executed and confirm whether to proceed
echo The following scripts will be executed in %DB%:
for /f "delims=" %%i in (ScriptsToImplement.txt) do echo %%i
echo:
set /p PROCEED=Proceed with implementation? [y/n] ^>
if /i "%PROCEED%" NEQ "y" (goto :opt_to_terminate)
:: Build the user profile SQL file that will be executed after logging into SQLPlus
:: This allows for the spooling of the output without having the SPOOL command declared in the file.
echo SET ECHO ON >> login.sql
echo SPOOL %DB%~%FOLDER%~%DATESTAMP%.log APPEND >> login.sql
:: Go through the SQL files in the text file and execute them in the specified database.
for /f "delims=" %%i in (ScriptsToImplement.txt) do (
echo exit | sqlplus -L -S %DB_USER%/%DB_PASS%@%DB% @%%i
if %errorlevel% NEQ 0 (@echo an error occurred with applying %%i; stopping further script execution... & pause & goto :terminate) else (@echo %%i was applied successfully) >> %DATESTAMP%_run_all.log
)
나의 이해, 그것은 login.sql를 파일마다 호출되어있다 : 여기
는 배치 스크립트에서 관련 코드 매번 SET ECHO ON 명령을 사용해야합니다.
이것은'echo exit | sqlplus -L -S % DB_USER %/% DB_PASS % @ % DB % @ %% i' 당신은 매번 login.sql을 호출하는 것으로 언급하고 있습니다. 그것이 작동하는 방법입니다. – Guru
스크립트에 SET ECHO OFF가 포함되어 있지 않음을 확인 했습니까? – dbenham
@dbenham 예, 스크립트를 작성했습니다. 유일한 DDL/DML은 ALTER SESSION 명령입니다. – sukach