So here it is. Script was tested with Oracle 10g on Windows 2000/XP/2003/2008.
:: Works for all Oracle databases pre-11g
:: %ORACLE_HOME% muste be defined (otherwise will produce an error 'Directory not found')
:: 11g have changes in a way that introduce universal "diagnostic_dest" parameter
:: which is not cover in this solution (will produce an error 'Directory not found')
:: Make Sure Listener name is passed
@if "%1" == "" goto QUIT_WITH_MESSAGE
@ECHO OFF
SETLOCAL
:: Set the Environment
@set DATUM=%date:~10,4%%date:~4,2%%date:~7,2%
@set VRIJEME=%time:~0,2%%time:~3,2%
@SET NOW=%DATUM%_%VRIJEME%
:: No need for upper and lower case values (Windows!)
@SET LSNR=%1
@if NOT EXIST %ORACLE_HOME%\network\log GOTO NOLOGDIR
@if NOT EXIST %ORACLE_HOME%\network\log\%LSNR%.log GOTO NOLOGFILE
%ORACLE_HOME%\bin\lsnrctl set current_listener %LSNR%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set log_file temp.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
copy %ORACLE_HOME%\network\log\%LSNR%.log %ORACLE_HOME%\network\log\%LSNR%.log.%NOW%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
@DEL %ORACLE_HOME%\network\log\%LSNR%.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set current_listener %LSNR%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set log_file %LSNR%.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
:: add content which has been logged in the meantime
@IF NOT EXIST %ORACLE_HOME%\network\log\temp.log GOTO END
@type %ORACLE_HOME%\network\log\temp.log >> %ORACLE_HOME%\network\log\%LSNR%.log.%NOW%
@DEL %ORACLE_HOME%\network\log\temp.log
GOTO END
:NOLOGFILE
@ECHO ON
@echo "File %ORACLE_HOME%\network\log\%LSNR%.log not found..."
@GOTO QUIT_WITH_MESSAGE
:NOLOGDIR
@ECHO ON
@echo "Directory %ORACLE_HOME%\network\log not found..."
@GOTO QUIT_WITH_MESSAGE
:QUIT_WITH_MESSAGE
@ECHO ON
@echo Usage: %0 LSNR
@echo where LSNR is full name of listener name in current %ORACLE_HOME% home
@echo Information:
@echo 'LSNR' value is case insensitive!
GOTO END
:ERR
@ECHO ON
@echo "There was some errors. Please look in directory %ORACLE_HOME%\network\log for some problem files."
@echo "Recheck lsnrctl configuration manually!"
GOTO END
:END
@ENDLOCAL
:: %ORACLE_HOME% muste be defined (otherwise will produce an error 'Directory not found')
:: 11g have changes in a way that introduce universal "diagnostic_dest" parameter
:: which is not cover in this solution (will produce an error 'Directory not found')
:: Make Sure Listener name is passed
@if "%1" == "" goto QUIT_WITH_MESSAGE
@ECHO OFF
SETLOCAL
:: Set the Environment
@set DATUM=%date:~10,4%%date:~4,2%%date:~7,2%
@set VRIJEME=%time:~0,2%%time:~3,2%
@SET NOW=%DATUM%_%VRIJEME%
:: No need for upper and lower case values (Windows!)
@SET LSNR=%1
@if NOT EXIST %ORACLE_HOME%\network\log GOTO NOLOGDIR
@if NOT EXIST %ORACLE_HOME%\network\log\%LSNR%.log GOTO NOLOGFILE
%ORACLE_HOME%\bin\lsnrctl set current_listener %LSNR%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set log_file temp.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
copy %ORACLE_HOME%\network\log\%LSNR%.log %ORACLE_HOME%\network\log\%LSNR%.log.%NOW%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
@DEL %ORACLE_HOME%\network\log\%LSNR%.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set current_listener %LSNR%
IF %ERRORLEVEL% NEQ 0 GOTO ERR
%ORACLE_HOME%\bin\lsnrctl set log_file %LSNR%.log
IF %ERRORLEVEL% NEQ 0 GOTO ERR
:: add content which has been logged in the meantime
@IF NOT EXIST %ORACLE_HOME%\network\log\temp.log GOTO END
@type %ORACLE_HOME%\network\log\temp.log >> %ORACLE_HOME%\network\log\%LSNR%.log.%NOW%
@DEL %ORACLE_HOME%\network\log\temp.log
GOTO END
:NOLOGFILE
@ECHO ON
@echo "File %ORACLE_HOME%\network\log\%LSNR%.log not found..."
@GOTO QUIT_WITH_MESSAGE
:NOLOGDIR
@ECHO ON
@echo "Directory %ORACLE_HOME%\network\log not found..."
@GOTO QUIT_WITH_MESSAGE
:QUIT_WITH_MESSAGE
@ECHO ON
@echo Usage: %0 LSNR
@echo where LSNR is full name of listener name in current %ORACLE_HOME% home
@echo Information:
@echo 'LSNR' value is case insensitive!
GOTO END
:ERR
@ECHO ON
@echo "There was some errors. Please look in directory %ORACLE_HOME%\network\log for some problem files."
@echo "Recheck lsnrctl configuration manually!"
GOTO END
:END
@ENDLOCAL
Cheers!
Looks promising. Will try immediately.
ReplyDeleteThank you for fulfilling my ask.
"Mr. Gorgy"
;-)
Welcome!
ReplyDeleteOdlican tekst!
ReplyDeleteDo sada sam to radio rucno, jer nisam bas vjest u batch-scriptingu, ali od sada cu koristiti tvoje rjesenje! :)
Hvala - ustedio si mi dosta truda i vremena! :)
Dejane,
ReplyDeleteDrago mi je da će nekome koristiti kao što koristi meni....