Mir Sayeed Hassan – Oracle Blog

Oracle DBA – Tips & Techniques | Learn with real-time examples

  • Translate

  • It’s Me






  • My Certificates

  • Links

    My Acclaim Certification : Credly Profile
    My Oracle ACE Pro Profile

  • Achievements

    Awarded Top 100 Oracle Blogs from Worldwide - #RANK 39
  • VISITORS COUNT

  • Verified International Academic Qualification from World Education Service (WES)

    Verified International Academic Qualification from World Education Service (WES)

  • Jobs

Script to Delete Log Files in Oracle Database by using the Crontab Job

Posted by Mir Sayeed Hassan on July 25th, 2018

Script to Delete Log Files in Oracle Database by using the Crontab Job

The given script is tested in our test env

The logfiles are deleTrace File i.e (,trc,.trm) , Audit File (.aud), Listener log (.trc,.trm) & .xml files

In order to manage space in better way, the best practice is to clear the logs files from the database as the logs will grow in big size, Therefore I created the scripts to clear those logs in a daily/weekly/monthly basis as per your requirement

Create a directory as shown below:

[oracle@testdb ~]$ cd /home/oracle/scripts

Create a .sh files by using vi editor

[oracle@localhost scripts]$ vi del_trc_trm_aud_xml_files.sh
[oracle@localhost scripts]$ cat del_trc_trm_aud_xml_files.sh

export ORACLE_SID=prim
find /u01/app/oracle/diag/rdbms/prim/prim/trace -type f -name "*.trc" -mtime +4 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/prim/prim/trace -type f -name "*.trm" -mtime +4 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/prim/prim/alert -type f -name "*.xml" -mtime +10 -exec rm {} \;
find /u01/app/oracle/diag/tnslsnr/localhost/listener/alert -type f -name "*.xml" -mtime +10 -exec rm {} \;
find /u01/app/oracle/diag/tnslsnr/localhost/listener1/alert -type f -name "*.xml" -mtime +10 -exec rm {} \;
find /u01/app/oracle/diag/tnslsnr/localhost/listener2/alert -type f -name "*.xml" -mtime +10 -exec rm {} \;
find /u01/app/oracle/diag/tnslsnr/localhost/listener3/alert -type f -name "*.xml" -mtime +10 -exec rm {} \;
find /u01/app/oracle/admin/prim/adump -type f -name "*.aud" -mtime +20 -exec rm {} \;
:wq

Before scheduling into the crontab, try to run it manually & verify

[oracle@localhost scripts]$ ./del_trc_trm_aud_xml_files.sh

In this case the scripts should run successfully

Now schedule it by using the crontab

[oracle@localhost scripts]$ crontab -l

###################################################
## Delete the old .trc,.trm,.xml,.aud files from DB
###################################################
00 5 * * * /home/oracle/scripts/del_trc_trm_aud_xml_files.sh

==========Hence tested & verified in our db env ================