{"id":152,"date":"2017-08-16T22:17:53","date_gmt":"2017-08-16T22:17:53","guid":{"rendered":"http:\/\/www.mrmarkyoung.com\/oracle\/?p=152"},"modified":"2017-08-16T22:17:53","modified_gmt":"2017-08-16T22:17:53","slug":"purge-oracle-maintenance-logs","status":"publish","type":"post","link":"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/16\/purge-oracle-maintenance-logs\/","title":{"rendered":"Purge Oracle Maintenance Logs"},"content":{"rendered":"<p>Purging Oracle Logs<\/p>\n<p>The basis of this script is to purge logs from the Oracle Base directory daily<\/p>\n<p>The script will be executed from cron on a daily basis, however this could run at different times on each system due to business and or system load requirements.<br \/>\nTechnical Steps<\/p>\n<pre class=\"lang:default decode:true \" >#!\/bin\/ksh\r\n#--------------------------------------------------------------------------------\r\n#--\r\n#-- File name:   purge_logs.sh\r\n#-- Purpose:     Script is used to purge all relevant logs from the Oracle Base location.\r\n#--              Remove Archive Logs older than one day\r\n#--\r\n#-- Author:      Mark Young\r\n#-- Copyright:   TOLL GIS\r\n#--\r\n#--\r\n#--------------------------------------------------------------------------------\r\n#--  Usage:\r\n#--  purge_logs.sh\r\n#--\r\n#--  Examples:\r\n#--  purge_logs.sh\r\n#--\r\n#--\r\n#--  Modified   (MM\/DD\/YY)\r\n#--  marky       6\/12\/11 - Creation\r\n#--\r\n#--  If any changes are made to this script, it must be updated in confluence\r\n#--\r\n#--  Location of this script\r\n#--  http:\/\/confluence.toll.com.au\/display\/OPSDBA\/Purge+Oracle+Log+Maintenance #--   RGM 9\/11\/12 - added UID to flag file for multiple users to use..\r\n#--------------------------------------------------------------------------------\r\n \r\nOracleBase=\/usr\/local\/oracle\/admin\r\n \r\n#Make sure the script isn't already runningIsRunning=\/tmp\/.isrunning\r\nLOGFILE=\/var\/local\/oracle\/log\/purge_log.log\r\nHOSTNAME=`hostname`\r\nDBAMAIL=dba_team@toll.com.au\r\nUID=`id -u`\r\nIsRunning=\"\/tmp\/.isrunning${UID}\"\r\n \r\nif [ -d \"$OracleBase\" ]; then\r\n        RC=0\r\nelse\r\n        echo \"Failed to find directory \/usr\/local\/oracle\/admin the script has stopped due to this error\" &gt; $LOGFILE\r\n        RC=1\r\nfi\r\n \r\n \r\nif [[ -f ${IsRunning} || ${RC} -gt 0 ]]; then\r\n        echo \"The script is already running.. Exiting\" &gt; $LOGFILE\r\n        RC=1\r\nelse\r\n        touch $IsRunning\r\n        echo \"The script is about to start\"\r\n \r\n        #Process trc files, but keep files for the past 30 days\r\n        find $OracleBase -mtime +30 -type f -name \"*.trc\" -exec rm -rf {} \\;\r\n \r\n        #Process AUD files, but keep files for the past 5 days\r\n        find $OracleBase -mtime +5 -type f -name \"*.aud\" -exec rm -rf {} \\;\r\n \r\n        #Process txt files, but keep files for the past 7 days\r\n        find $OracleBase -mtime +7 -type f -name \"*.txt\" -exec rm -rf {} \\;\r\n \r\n        #Process txt files, but keep files for the past 5 days\r\n        #turned this off, Oracle 12c agent creates a directory called core which is removed by this script\r\n        #find $OracleBase -mtime +5 -type d -name core -exec rm -rf {} \\;\r\n \r\n        #Remove the file for next time.\r\n        rm $IsRunning\r\n        RC=$?\r\nfi\r\n \r\n \r\n        if [ $RC -ne \"0\" ]; then\r\n                echo \"The script failed and needs your attention\" &gt;&gt; $LOGFILE\r\n                rm $IsRunning\r\n                mailx -s \"purge_log.sh has failed on $HOSTNAME, this needs your attention\" $DBAMAIL &lt; $LOGFILE\r\n        fi<\/pre>\n<p><strong>Change permissions on this file<\/strong><\/p>\n<pre class=\"lang:default decode:true \" >chmod +x \/usr\/local\/oracle\/admin\/scripts\/ksh\/purge_logs.sh<\/pre>\n<p><strong>Crontab Entry<\/strong><\/p>\n<pre class=\"lang:default decode:true \" ># oracle crontab placeholder\r\n#  .---------------- minute (0 - 59)\r\n#  |   .------------- hour (0 - 23)\r\n#  |   |   .---------- day of month (1 - 31)\r\n#  |   |   |   .------- month (1 - 12) OR jan,feb,mar,apr ...\r\n#  |   |   |   |  .----- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat\r\n#  |   |   |   |  |\r\n#  *   *   *   *  *  command to be executed\r\n\r\n30 6 * * * \/usr\/local\/oracle\/admin\/scripts\/ksh\/purge_logs.sh &gt; \/dev\/null 2&gt;&amp;1<\/pre>\n<p><strong><em>>Known Issues<\/em><\/strong><br \/>\nMust be run on a system 10g or earlier. We are going to be using ADRCI for 11g<\/p>\n<p><strong><em>Applies to:<\/em><\/strong><em><br \/>\nOracle Version: 10g and earlier. Information in this document applies to any platform.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Purging Oracle Logs The basis of this script is to purge logs from the Oracle Base directory daily The script will be executed from cron on a daily basis, however this could run at different times on each system due to business and or system load requirements. Technical Steps #!\/bin\/ksh #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; #&#8211; #&#8211; File name: &#8230; <a title=\"Purge Oracle Maintenance Logs\" class=\"read-more\" href=\"http:\/\/www.mrmarkyoung.com\/oracle\/2017\/08\/16\/purge-oracle-maintenance-logs\/\" aria-label=\"Read more about Purge Oracle Maintenance Logs\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,20],"tags":[41],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-oracle-database","category-unix","tag-purge"],"_links":{"self":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":2,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":154,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/posts\/152\/revisions\/154"}],"wp:attachment":[{"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrmarkyoung.com\/oracle\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}