#!/bin/bash

ORACLE_HOME=${ORACLE_HOME:-/opt/app/oracle/product/10.2.0/db_1}
SUFFIX=`date -d "1 month ago" +"%Y%m"`
LISTENER_LOG_FILE=listener_`hostname | tr '[A-Z]' '[a-z]'`
LISTENER_LOG_DIR=${ORACLE_HOME}/network/log

cd ${LISTENER_LOG_DIR}

${ORACLE_HOME}/bin/lsnrctl set log_file ${LISTENER_LOG_FILE}.tmp.log

/bin/mv ${LISTENER_LOG_FILE}.log ${LISTENER_LOG_FILE}.${SUFFIX}.log

${ORACLE_HOME}/bin/lsnrctl set log_file ${LISTENER_LOG_FILE}.log

/bin/cat ${LISTENER_LOG_FILE}.tmp.log >> ${LISTENER_LOG_FILE}.${SUFFIX}.log

/bin/tar zcf ${LISTENER_LOG_FILE}.${SUFFIX}.log.tar.gz ${LISTENER_LOG_FILE}.${SUFFIX}.log

/bin/rm -f ${LISTENER_LOG_FILE}.tmp.log
/bin/rm -f ${LISTENER_LOG_FILE}.${SUFFIX}.log

exit 0