Forum Stats

  • 3,826,863 Users
  • 2,260,714 Discussions


rotating listener.log files on Oracle 10g/11g through OEM

user2522172 Member Posts: 111
edited Apr 19, 2012 12:33PM in General Database Discussions

We manage quite Oracle databases (mainly 10g/11g) through OEM and we see that listener.log files are becoming quite big in size. Oracle 11g has also and listener.xml file and this file is automatically rotated when it becomes bigger>10Mbyte. The listener.log file is not rotated. This is also true for 10g.
I've written a perl script which we will execute through OEM in order to rotate the log file:

------------------------------------------- START script --------------------------------------------
$lp = `ps -ef|grep tnslsnr|grep -v grep`; # get listener process info
$lp =~ s/.* \//\//; # remove all characters froom start line till first /
($pad,$rest) = split(/ /,$lp); # $pad contains path to executable (e.g. /opt/sw/oracle/product/10204/bin/tnslsnr)

$ohome = $pad;
$ohome =~ s/\/bin\/tnslsnr//; # get oracle home directory from where listener is running

$pad = $ohome."/bin"; # get path to tnslsnr execv

$ENV{'ORACLE_HOME'} = $ohome; # set environment: ORACLE_HOME and PATH
$ENV{'PATH'} = "$pad:$ENV{'PATH'}";

$l= "lsnrctl";
open LS,"$l status |" or die "drop dead"; # execute lsnrctl status in order to get listener-log file name and location
while (<LS>) {
if (/Listener Log File/) { $lgfo = $_;$lgfo =~ s/Listener Log File \s+//;}

close LS;

open LS,"| $l" or die "drop dead"; # create a new, temporary log-file on /tmp
print LS qq|
set log_file '/tmp/$$.log'

close LS;

rename( "$lgfo", "${lgfo}.$$"); # rename original listener.log file to something else

open LS,"| $l" or die "drop dead"; # create new listener.log file
print LS qq|
set log_file $lgfo

close LS;
unlink "/tmp/$$.log"; # remove temporary log-file on /tmp (some listener log info could be lost!)'

------------------------------------------- END script --------------------------------------------

This script will not work on machines with different listeners (script should be adapted) but with us that is not the case.
What do you think about this solution? are there better ones? Thanks in advance.




This discussion has been closed.