Managing listener.log and log.xml with Linux Logrotate

Hi all,
To manage Oracle trace files the way to go is ADRCI. You can see this post from Matheus if you have not read it yet.

In the last part of the script we have a small bash code to configure the ADRCI on all databases running on a server

You could add:

adrci exec="set home $1;purge -age 10080 -type ALERT";

In this case the age parameter is in minutes but still you would be required to run it periodically which could be another script in crontab to be managed.

SO the solution that I found to be best as it takes leverage from an existing solution is called logrotate.

Logrotate is a Unix/Linix based program that helps as its name says, rotate any file that you need. You just need to create a configuration file and place it on /etc/logrotate.d on most Linuxes distributions.

But when you have a server with several databases and listerners and more, it starts to get a bit tedious and time consuming to create this manually.

In this post on the Pythian Blog, will find how to create but it does not handle the listener.log but not the log.xml so I added this piece here

for L in `\ps -ef | grep tnslsnr | grep -v grep | sed s'/-.*$//g' | awk '{print $NF}'`
LSRN_LOG=`lsnrctl status ${L} | grep "Listener Log File" | awk '{print $NF}'`
echo ${LSRN_LOG%.*}"*" " {" > ${OUT}
cat << ! >> ${OUT}
rotate 1
echo ${OUT} has been generated

Using logroate really helps on the managing on Oracle related files which are not done by ADRCI.

Hope it helps,


Script to Setup ADRCI Policies

Hi all!
So, today just sharing some useful scripts to configure, set and check on databases and users.

This is specially useful for environments with several databases under different users, considering a possible server consolidation strategy.

# Script to Check on Current Configuration:

[root@greporasrv ~]# cat
su - $1 -c 'export ORAENV_ASK=NO ; ORACLE_SID=$2 ; . oraenv ; for f in $(adrci exec="show homes" | grep -v "ADR Homes:" | grep -v "clients") ; do adrci exec="set home $f; show control;" ; done'

# Script to Set New Configuration
On this example: (SHORTP_POLICY = 168, LONGP_POLICY = 720).

[root@greporasrv ~]# cat
export SID=$2
su - $ORAUSER -c 'export ORAENV_ASK=NO ; ORACLE_SID='$SID' ; . oraenv ; for f in $(adrci exec="show homes" | grep -v "ADR Homes:" | grep -v "clients") ; do adrci exec="set home $f; set control \(SHORTP_POLICY = 168, LONGP_POLICY = 720\);" ; done'

# To run them informing OSUSER and SID:


# Master one: Script to set for all DBs/Users:

[root@greporasrv ~]# cat
for h in $(grep -v "^#" /etc/oratab | awk 'BEGIN { FS=":";} {if (NF) print $2}' | sort -u)
ORAOWN=`ls -ld $h | cut -d " " -f 3`
# validate user?
# get a SID to use for this home
SID=`grep $h /etc/oratab | grep -v '^\*:' | cut -d ":" -f 1 | tail -1`

# Generating the code to check ADRCI settings on this OH

# Generating the code to change ADRCI settings on this OH

Nice, right?
Hope it helps. Cheers!