Pages

Monday, June 19, 2017

delete_old_trace_files.sh. Linux script to delete Oracle log files

===========================
General
===========================
This a script that cleans up log file for Oracle listener and server.

===========================
Code
===========================

crontab entry
0 6 * * * /software/oracle/oracle/scripts/delete_old_trace_files.sh

delete_old_trace_files.sh


#!/bin/bash
ORA_INST=igt
DAYS_TO_KEEP=14
DAYS_TO_KEEP_LIST=7
LIST_SERVER=`hostname`

LISTENER_ROOT=/software/oracle/diag/tnslsnr/${LIST_SERVER}/lsnr_igt/trace
LISTENER_ROOT_ALERT=/software/oracle/diag/tnslsnr/${LIST_SERVER}/lsnr_igt/alert

find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/trace -type f -name "*.trc" -mtime +${DAYS_TO_KEEP} -exec rm {} \;
find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/trace -type f -name "*.trm" -mtime +${DAYS_TO_KEEP} -exec rm {} \;
find /software/oracle/diag/rdbms/${ORA_INST}/${ORA_INST}/trace -type f -size +1000M -exec rm {} \;

find $LISTENER_ROOT  -type f -mtime +${DAYS_TO_KEEP} -exec rm {} \;
find $LISTENER_ROOT_ALERT  -type f -mtime +${DAYS_TO_KEEP_LIST} -exec rm {} \;

mv -f  ${LISTENER_ROOT}/lsnr_igt.log_6  ${LISTENER_ROOT}/lsnr_igt.log_7
mv -f  ${LISTENER_ROOT}/lsnr_igt.log_5  ${LISTENER_ROOT}/lsnr_igt.log_6
mv -f  ${LISTENER_ROOT}/lsnr_igt.log_4  ${LISTENER_ROOT}/lsnr_igt.log_5
mv -f  ${LISTENER_ROOT}/lsnr_igt.log_3  ${LISTENER_ROOT}/lsnr_igt.log_4
mv -f  ${LISTENER_ROOT}/lsnr_igt.log_2  ${LISTENER_ROOT}/lsnr_igt.log_3
mv -f  ${LISTENER_ROOT}/lsnr_igt.log_1  ${LISTENER_ROOT}/lsnr_igt.log_2
mv -f  ${LISTENER_ROOT}/lsnr_igt.log    ${LISTENER_ROOT}/lsnr_igt.log_1


===========================
Evaluate the current status
===========================
Find biggest files
find /some/path -type f -printf '%s %p\n'|sort -nr | head -10 

Find biggest folder
du  -sh * |sort -nr | head -10

No comments:

Post a Comment