Tuesday, May 25, 2010

Rotate listener log (TNS-12547, TNS-12560, TNS-00517) Part II

In mine previous post I have shown how to rotate listener on Linux environment. First comment from certain Mr. Gorgy was why there is no where to find Windows version for the same purpose.

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

Cheers!

4 comments :

  1. Looks promising. Will try immediately.
    Thank you for fulfilling my ask.
    "Mr. Gorgy"
    ;-)

    ReplyDelete
  2. Odlican tekst!
    Do 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! :)

    ReplyDelete
  3. Dejane,

    Drago mi je da će nekome koristiti kao što koristi meni....

    ReplyDelete

Zagreb u srcu!

Copyright © 2009-2014 Damir Vadas

All rights reserved.


Sign by Danasoft - Get Your Sign