Oracle脚本(三)

来源:互联网 发布:编程语言难学吗 编辑:程序博客网 时间:2024/05/05 05:22

   Oracl自动保存当天的alert日志文件到当月的目录下,方便日志的查看和归类。参考网上文章,修改了自己的一份脚本。

  1. #!/bin/bash    
  2. ORACLE_SID=orcl; export ORACLE_SID   
  3. ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE   
  4. ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1; export ORACLE_HOME   
  5. DBALIST="masicong1019@hotmail.com";export DBALIST    
  6. export MAIL_DIR=/usr/local/bin   
  7. export MAIL_LIST='masicong1019@outlook.com'   
  8. export MAIL_FM='masicong1019@outlook.com'   
  9. ORACLE_SID=orcl;  export ORACLE_SID   
  10. db_stat=`ps -ef | grep pmon_$ORACLE_SID | grep -v grep| cut -f3 -d_`   
  11. if [ -z "$db_stat" ]; then   
  12.     echo " $ORACLE_SID is not available on `hostname` !!!"     
  13.     MAIL_SUB=" $ORACLE_SID is not available on `hostname` !!!"   
  14.     MAIL_MSG="$ORACLE_SID is not available on `hostname` before age alert log file, exit,  
  15.  
  16. please check !"   
  17.     $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -m $MAIL_MSG   
  18.     exit 1   
  19. fi   
  20. DUMP_DIR=`sqlplus -S '/ as sysdba' << EOF   
  21. set pagesize 0 feedback off verify off heading off echo off   
  22. SELECT value FROM  v\\$parameter WHERE  name = 'background_dump_dest';   
  23. exit   
  24. EOF   
  25. if [ -z ${DUMP_DIR} ]; then   
  26.     echo "The bdump directory was not found for ${ORACLE_SID}"   
  27.     MAIL_SUB="The bdump directory was not found for ${ORACLE_SID}"   
  28.     MAIL_MSG="The bdump directory was not found for ${ORACLE_SID} on `hostname` before  
  29.  
  30. age log file,exit,please check !"   
  31.     $MAIL_DIR/sendEmail -u $MAIL_SUB -f $MAIL_FM -t $MAIL_LIST -m $MAIL_MSG   
  32.     exit 1   
  33. else   
  34.     echo ${DUMP_DIR}   
  35. fi   
  36. DT=`date +%Y%m%d -d '-1 day'`   
  37. OLD_DIR=${DT:0:6}   
  38. NEW_DIR=`date +%Y%m`   
  39. ORIG_ALERT_LOG=${DUMP_DIR}/alert_${ORACLE_SID}.log   
  40. OLD_ARC_DIR=${DUMP_DIR}/${OLD_DIR}   
  41. NEW_ARC_DIR=${DUMP_DIR}/${NEW_DIR}   
  42.    
  43. if [ ! -d "${NEW_ARC_DIR}" ] ; then   
  44.     mkdir ${NEW_ARC_DIR}   
  45. fi   
  46.    
  47. if [ "${OLD_DIR}" \< "${NEW_DIR}" ];then   
  48.     ARC_LOG=${OLD_ARC_DIR}/alert_${ORACLE_SID}.log.${DT}   
  49. else   
  50.     ARC_LOG=${NEW_ARC_DIR}/alert_${ORACLE_SID}.log.${DT}   
  51. fi   
  52. cat ${ORIG_ALERT_LOG} >>${ARC_LOG}   
  53. cat /dev/null>${ORIG_ALERT_LOG}   
  54. exit   

 

本文出自 “无双城” 博客,请务必保留此出处http://929044991.blog.51cto.com/1758347/1179903

原创粉丝点击