Guest User

Untitled

a guest
Feb 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. #############################################################################################################################################################
  2. #!/bin/bash
  3. #############################################################################################################################################################
  4.  
  5. TODAY=`date +%Y-%m-%d`
  6. DATE=`date +%Y%b%d`
  7. YESTERDAY=`date -d '-1 day' +%b%Y`
  8. YDAY=`date -d '-1 day' +%Y%b%d`
  9. HOST=`hostname`
  10. LOG_LOCATION="/home/oracle/utility_script/dba_maint/logs"
  11.  
  12. mkdir -p ${LOG_LOCATION}
  13.  
  14. LOG_FILE="${LOG_LOCATION}/oracle_files_cleanup_${DATE}.log"
  15.  
  16. rm ${LOG_FILE} 2>/dev/null
  17.  
  18. dbenv ()
  19. {
  20. ORACLE_HOME=`cat /etc/oratab | grep ^$ORACLE_SID | cut -d":" -f2`; export ORACLE_HOME
  21. PATH=$ORACLE_HOME/bin:$PATH ; export PATH
  22. LD_LIBRARY_PATH=$ORACLE_HOME/lib ; export LD_LIBRARY_PATH
  23. DB_VERSION=`cat /etc/oratab | grep "^$ORACLE_SID" | cut -d":" -f2 | rev | cut -d"/" -f2| rev | cut -d"." -f1`; export DB_VERSION
  24. }
  25.  
  26.  
  27. dbcheck()
  28. {
  29. sqlplus / as sysdba << EOF &>${LOG_LOCATION}/dbcheck.out
  30. exit
  31. EOF
  32. }
  33.  
  34. sql_plus()
  35. {
  36. sqlplus -s / as sysdba << EOF &>/dev/null
  37. SET NEWPAGE NONE;
  38. set lines 200 pages 300;
  39. set feedback off;
  40. set heading off;
  41. spool ${LOG_LOCATION}/$1.log
  42. $2
  43. exit
  44. EOF
  45. }
  46.  
  47. for SID in `ps -eaf | grep pmon | grep -v grep | awk '{print $8}' | sort | cut -d"_" -f3`
  48. do
  49. ORACLE_SID=${SID} ; export ORACLE_SID
  50. dbenv ${ORACLE_SID} #-- Passing the ORACLE_SID to dbenv function to source the database.
  51. if [ ${DB_VERSION} -eq 11 -o ${DB_VERSION} -eq 12 ]
  52. then
  53. dbcheck
  54. DB_CHECK=`cat ${LOG_LOCATION}/dbcheck.out | egrep "ORA|SP2|idle"`
  55. LOWER_SID=`echo ${ORACLE_SID} | tr '[A-Z]' '[a-z]'`
  56.  
  57. #-- Queries to fetch the proper log location from database
  58.  
  59. ADUMP="select DISPLAY_VALUE from v$parameter where name='audit_file_dest';"
  60. BDUMP="select DISPLAY_VALUE from v$parameter where name='background_dump_dest';"
  61. CDUMP="select DISPLAY_VALUE from v$parameter where name='core_dump_dest';"
  62. UDUMP="select DISPLAY_VALUE from v$parameter where name='user_dump_dest';"
  63. TRACE_FILE="select DISPLAY_VALUE from v$parameter where name='diagnostic_dest';"
  64.  
  65. #-- Calls the sql_plus function with the parameters as the logname and SQL query
  66.  
  67. sql_plus "adump_${ORACLE_SID}" "${ADUMP}"
  68. sql_plus "bdump_${ORACLE_SID}" "${BDUMP}"
  69. sql_plus "cdump_${ORACLE_SID}" "${CDUMP}"
  70. sql_plus "udump_${ORACLE_SID}" "${UDUMP}"
  71. sql_plus "trace_${ORACLE_SID}" "${TRACE_FILE}"
  72.  
  73. #-- Remove any empty lines after the log location
  74.  
  75. ADUMP_LOC=`cat ${LOG_LOCATION}/adump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  76. BDUMP_LOC=`cat ${LOG_LOCATION}/bdump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  77. CDUMP_LOC=`cat ${LOG_LOCATION}/cdump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  78. UDUMP_LOC=`cat ${LOG_LOCATION}/udump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  79. TRACE_LOC=`cat ${LOG_LOCATION}/trace_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  80.  
  81. #-- If the Database is not in idle state or without any errors, start housekeeping
  82.  
  83. if [ -z "${DB_CHECK}" ]
  84. then
  85. echo -e "tttt HOUSEKEEPING for database : ${ORACLE_SID}" >>${LOG_FILE}
  86. echo -e "tttt ============ === ======== = =============" >>${LOG_FILE}
  87.  
  88. #-- Cleans .aud files older than 60 days in ADUMP location
  89.  
  90. if [ ! -z "${ADUMP_LOC}" ]
  91. then
  92. echo -e "tttAdump cleanup" >> ${LOG_FILE}
  93. fi
  94.  
  95. #-- Cleans .trm or .trc files older than 60 days in BDUMP location
  96.  
  97. if [ ! -z "${BDUMP_LOC}" ]
  98. then
  99. echo -e "nntttBdump cleanup" >> ${LOG_FILE}
  100. fi
  101.  
  102. #-- Cleans .trm or .trc files older than 60 days in CDUMP location
  103.  
  104. if [ ! -z "${CDUMP_LOC}" ]
  105. then
  106. echo -e "ntttCdump cleanup" >> ${LOG_FILE}
  107. fi
  108.  
  109. #-- Cleans .trm or .trc files older than 60 days in UDUMP location
  110.  
  111. if [ ! -z "${UDUMP_LOC}" ]
  112. then
  113. echo -e "ntttUdump cleanup" >> ${LOG_FILE}
  114. fi
  115.  
  116. #-- Rotates the Database alert log on 01st of every month.
  117.  
  118. if [ `date +%d` -eq 01 ]
  119. then
  120. if [ ! -z "${TRACE_LOC}" ]
  121. then
  122. echo -e "ntttALERT LOG ROTATION" >> ${LOG_FILE}
  123. fi
  124. fi
  125.  
  126. #-- Rotates the Listener log on 01st of every month.
  127.  
  128. if [ `date +%d` -eq 01 ]
  129. if [ ! -z "${TRACE_LOC}" ]
  130. then
  131. echo -e "ntttLISTENER LOG ROTATION" >> ${LOG_FILE}
  132. fi
  133. fi
  134. else
  135. echo -e "ERROR : Please fix the below error in database - ${ORACLE_SID} on host - ${HOST} n ${DB_CHECK}" >> ${LOG_LOCATION}/house_keeping_fail_${ORACLE_SID}_${DATE}.log
  136. fi
  137. elif [ ${DB_VERSION} -eq 10 -o ${DB_VERSION} -eq 9 ]
  138. then
  139. dbcheck
  140. DB_CHECK=`cat ${LOG_LOCATION}/dbcheck.out | egrep "ORA|SP2|idle"`
  141.  
  142. #-- Queries to fetch the proper log location from database
  143.  
  144. ADUMP="select DISPLAY_VALUE from v$parameter where name='audit_file_dest';"
  145. BDUMP="select DISPLAY_VALUE from v$parameter where name='background_dump_dest';"
  146. CDUMP="select DISPLAY_VALUE from v$parameter where name='core_dump_dest';"
  147. UDUMP="select DISPLAY_VALUE from v$parameter where name='user_dump_dest';"
  148.  
  149. #-- Calls the sql_plus function with the parameters as the logname and SQL query
  150.  
  151. sql_plus "adump_${ORACLE_SID}" "${ADUMP}"
  152. sql_plus "bdump_${ORACLE_SID}" "${BDUMP}"
  153. sql_plus "cdump_${ORACLE_SID}" "${CDUMP}"
  154. sql_plus "udump_${ORACLE_SID}" "${UDUMP}"
  155.  
  156. #-- Remove any empty lines after the log location
  157.  
  158. ADUMP_LOC=`cat ${LOG_LOCATION}/adump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  159. BDUMP_LOC=`cat ${LOG_LOCATION}/bdump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  160. CDUMP_LOC=`cat ${LOG_LOCATION}/cdump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  161. UDUMP_LOC=`cat ${LOG_LOCATION}/udump_${ORACLE_SID}.log | sed 's/[[:blank:]]*$//'`
  162.  
  163. #-- If the Database is not in idle state or without any errors, start housekeeping
  164.  
  165. if [ -z "${DB_CHECK}" ]
  166. then
  167. #-- Cleans .aud files older than 60 days in ADUMP location
  168.  
  169. if [ ! -z "${ADUMP_LOC}" ]
  170. echo -e "tttAdump cleanup" >> ${LOG_FILE}
  171. fi
  172.  
  173. #-- Cleans .trm or .trc files older than 60 days in BDUMP location
  174.  
  175. if [ ! -z "${BDUMP_LOC}" ]
  176. then
  177. echo -e "nntttBdump cleanup" >> ${LOG_FILE}
  178. fi
  179.  
  180. #-- Cleans .trm or .trc files older than 60 days in CDUMP location
  181.  
  182. if [ ! -z "${CDUMP_LOC}" ]
  183. then
  184. echo -e "ntttCdump cleanup" >> ${LOG_FILE}
  185. fi
  186.  
  187. #-- Cleans .trm or .trc files older than 60 days in UDUMP location
  188.  
  189. if [ ! -z "${UDUMP_LOC}" ]
  190. then
  191. echo -e "ntttUdump cleanup" >> ${LOG_FILE}
  192. fi
  193.  
  194. #-- Rotates the ${DB_VERSION} version Database alert log on 01st of every month.
  195.  
  196. if [ `date +%d` -eq 01 ]
  197. then
  198. if [ ! -z "${BDUMP_LOC}" ]
  199. then
  200. echo -e "ntttALERT LOG ROTATION" >> ${LOG_FILE}
  201. fi
  202. fi
  203. else
  204. echo -e "ERROR : Please fix the below error in database - ${ORACLE_SID} on host - ${HOST} n ${DB_CHECK}" >> ${LOG_LOCATION}/house_keeping_fail_${ORACLE_SID}_${DATE}.log
  205. fi
  206. fi
  207. done
  208. exit $?
  209. #---------------------------------------------------------------------END-----------------------------------------------------------------------------------#
Add Comment
Please, Sign In to add comment