Please find the below steps to rotate a listener logs.
The first parameter is simply the database SID represented as $1 and the second parameter is full path of the current listener log.
The first parameter is simply the database SID represented as $1 and the second parameter is full path of the current listener log.
# rotate_listener_log.sh
. ~/env/${1}_ORACLE
LOGFILE=${2}
DATE_STAMP=`date +%m%d%y%s`
lsnrctl <<END
set current_listener ${1}
set log_status off
exit
END
mv $LOGFILE $LOGFILE.${DATE_STAMP}
lsnrctl <<END
set current_listener ${1}
set log_status on
exit
END
zip $LOGFILE.${DATE_STAMP}.zip $LOGFILE.${DATE_STAMP}
rm $LOGFILE.${DATE_STAMP}
Please use the below script in action.
$ ls -ltr $LISTENER_LOG_HOME
total 41316
-rw-rw-r-- 1 oradevl dba 2663 Jun 10 10:23 dev.log.0610111307715830.zip
-rw-rw---- 1 oradevl dba 888 Jun 10 10:23 dev.log
$ ./rotate_listener_log.sh DEV /u01/appdevl/oracle/devdb/11.1.0/log/diag/tnslsnr/myhost/dev/trace/dev.log
LSNRCTL for Linux: Version 11.1.0.7.0 - Production on 10-JUN-2011 10:24:59
Copyright (c) 1991, 2008, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> Current Listener is DEV
LSNRCTL> Connecting to (ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROCDEV))
DEV parameter "log_status" set to OFF
The command completed successfully
LSNRCTL>
LSNRCTL for Linux: Version 11.1.0.7.0 - Production on 10-JUN-2011 10:24:59
Copyright (c) 1991, 2008, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> Current Listener is DEV
LSNRCTL> Connecting to (ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROCDEV))
DEV parameter "log_status" set to ON
The command completed successfully
LSNRCTL> adding: u01/appdevl/oracle/devdb/11.1.0/log/diag/tnslsnr/myhost/dev/trace/dev.log.0610111307715899 (deflated 80%)
$ ls -ltr $LISTENER_LOG_HOME
total 41320
-rw-rw-r-- 1 oradevl dba 2663 Jun 10 10:23 dev.log.0610111307715830.zip
-rw-rw-r-- 1 oradevl dba 579 Jun 10 10:24 dev.log.0610111307715899.zip
-rw-rw---- 1 oradevl dba 931 Jun 10 10:25 dev.log
Please put it in ur cron once everything is set.crontab -l
# cleanup listener logs
15 3 1 * * /usr/bin/find /u01/appdevl/oracle/devdb/11.1.0/log/diag/tnslsnr/myhost/dev/trace -mtime +365 -exec rm -rf {} \;
# rotate listener logs
0 0 1 * * /scratch/oracle/dba/scripts/rotate_listener_log.sh DEV /u01/appdevl/oracle/devdb/11.1.0/log/diag/tnslsnr/myhost/dev/trace/dev.log