This code cleans up old trace files, log files, core dumps, etc. It is designed to be run from cron. It takes a somewhat brutal approach by deleting files after just 7 days – good for e.g. dev/test servers, but in production you would probably want to modify this to keep files for longer.
For this example all oracle files of interest were under directory “/ora” – that would need to be changed to suit other sites.
# 1) Remove old oracle-owned aud, trc, trw, core files
# Also remove old recv error files (these have format ".err_[0-9]")
# Also remove access_log.
# Only core files named "core.
echo "*** REMOVE OLD ORACLE AUDIT FILES and OLD RECV Error Files and OLD TRACE FILES ***"
find /ora -mtime +7 -user oracle \( \
-name '*.aud' -o \
-name '*.trc*' -o \
-name '*.trw' -o \
-name 'core.[0-9]*' -o \
-name '*.err_[0-9]*' -o \
-name 'access_log.[0-9]*' -o \
-name 'error_log.[0-9]*' -o \
-name 'emoms.log.[0-9]*' \) -exec rm {} \;
# 2) Cut down alert logs and listener logs, and also access_log and event_log (webcache/portal/etc.)
# Old log files are ignored - only log files modified in the last 7 days are worked on.
# Small log files are ignored - only files bigger than 3mb (=6144*512 byte blocks) are worked on. 3mb is approximately 30,000 lines of text.
echo "*** CUT DOWN THE ALERT LOGS and ORACLE LISTENER.LOG FILE ***"
for FILE in `find /ora -mtime -7 -size +6144 -user oracle \( \
-name 'alert_*.log' -o \
-name 'listener*.log' -o \
-name 'access_log' -o \
-name 'event_log' -o \
-name 'http-web-access.log' -o \
-name 'server.log' \)`
do
echo "*** cutting $FILE ***"
cp $FILE $FILE.tmp
tail -10000 $FILE.tmp > $FILE
rm $FILE.tmp
done
echo "*** CUT DOWN MESSAGES and WARN FILES ***"
for FILE in `find /var/log/ -mtime -7 -size +6144 \( \
-name 'messages' -o \
-name 'warn' \)`
do
echo "*** cutting $FILE ***"
cp $FILE $FILE.tmp
tail -10000 $FILE.tmp > $FILE
rm $FILE.tmp
done
# End of file.