rotate_alert_logs_alertlog_with_shell_script
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| rotate_alert_logs_alertlog_with_shell_script [2018/12/08 12:49] – created 0.0.0.0 | rotate_alert_logs_alertlog_with_shell_script [2019/01/30 11:32] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Rotate_alert_logs_(alertlog)_with_shell_script ====== | ||
| - | |||
| < | < | ||
| - | #!/ | + | - !/ |
| - | # ============================================================================== | + | |
| - | # Name : maint_rotate_alertlog.ksh | + | |
| - | # Description | + | |
| - | # | + | |
| - | # Parameters | + | |
| - | # | + | |
| - | # | + | |
| - | # | + | |
| - | # | + | |
| - | # Notes : Ensures at least a month is kept even if someone | + | |
| - | # | + | |
| - | # | + | |
| - | # Modification History | + | |
| - | # ==================== | + | |
| - | # When Who | + | |
| - | # ========= ================= ================================================== | + | |
| - | # 12-SEP-13 Stuart Barkley | + | |
| - | # ============================================================================== | + | |
| ORATAB="/ | ORATAB="/ | ||
| Line 27: | Line 25: | ||
| DEF_ALERTLOG_AGE=30 | DEF_ALERTLOG_AGE=30 | ||
| - | # ======================================= | + | - |
| - | # thats it, nothing to change below here! | + | |
| - | # ======================================= | + | |
| PROGNAME=`basename $0` | PROGNAME=`basename $0` | ||
| Line 41: | Line 39: | ||
| - | # ------------------------------------------- | + | - |
| - | # dont run around trying to find oratab, | + | |
| - | # just get them to put it in a standard place | + | |
| - | # ------------------------------------------- | + | |
| [[ ! -r $ORATAB ]] && echo " | [[ ! -r $ORATAB ]] && echo " | ||
| - | # ------------------------- | + | - |
| - | # get the arguments, if any | + | |
| - | # ------------------------- | + | |
| while getopts " | while getopts " | ||
| do | do | ||
| Line 63: | Line 61: | ||
| - | # -------------------------------- | + | - |
| - | # check we have required arguments | + | |
| - | # -------------------------------- | + | |
| [[ -z $ORACLE_SID ]] && echo "Not all mandatory parameters supplied. Usage: $0 -s < | [[ -z $ORACLE_SID ]] && echo "Not all mandatory parameters supplied. Usage: $0 -s < | ||
| - | # ------------------------------------------------------- | + | - |
| - | # set the optional parameters to defaults if not supplied | + | |
| - | # ------------------------------------------------------- | + | |
| VERSIONS=${VERSIONS: | VERSIONS=${VERSIONS: | ||
| ROTATE_PERIOD=${ROTATE_PERIOD: | ROTATE_PERIOD=${ROTATE_PERIOD: | ||
| Line 77: | Line 75: | ||
| - | # ------------------------------- | + | - |
| - | # check the supplied SID is valid | + | |
| - | # ------------------------------- | + | |
| $GREP -q -E " | $GREP -q -E " | ||
| [[ $? -ne 0 ]] && echo " | [[ $? -ne 0 ]] && echo " | ||
| - | # ------------------------------------------ | + | - |
| - | # check we are running as the database owner | + | |
| - | # ------------------------------------------ | + | |
| - | DB_STARTED_AS=`ps -ef | $GREP [p]mon | $GREP $ORACLE_SID | $AWK ' | + | DB_STARTED_AS=`ps -ef | $GREP [[p]]mon | $GREP $ORACLE_SID | $AWK ' |
| WE_ARE=`$ID -un` | WE_ARE=`$ID -un` | ||
| [[ " | [[ " | ||
| - | # ------------------------------------------------------------------- | + | - |
| - | # setup the Oracle environment so we can find the alert log directory | + | |
| - | # ------------------------------------------------------------------- | + | |
| ORAENV_ASK=NO | ORAENV_ASK=NO | ||
| . oraenv | . oraenv | ||
| - | # ----------------------------------------------- | + | - |
| - | # Now we can get the ALERT_PATH from the database | + | |
| - | # ----------------------------------------------- | + | |
| ALERT_PATH=`sqlplus -s "/ as sysdba"<< | ALERT_PATH=`sqlplus -s "/ as sysdba"<< | ||
| set pages 0 | set pages 0 | ||
| set feedb off | set feedb off | ||
| - | select value from v\\$diag_info where lower(name) = 'diag trace'; | + | select value from v\\\\$diag_info where lower(name) = 'diag trace'; |
| EOSQL | EOSQL | ||
| ` | ` | ||
| Line 114: | Line 112: | ||
| - | # --------------------------------------------------- | + | |
| - | # Ensure the oldest alert log is older than permitted | + | - |
| - | # --------------------------------------------------- | + | - --------------------------------------------------------- |
| - | if [[ -e " | + | |
| - | CNT=`find . -name " | + | |
| - | if [[ $CNT -eq 0 ]]; then | + | |
| - | echo " | + | |
| - | | + | |
| - | for i in `find . -name " | + | |
| - | echo ". deleting "$i; rm $i | + | |
| - | done | + | |
| - | fi | + | |
| - | fi | + | |
| - | + | ||
| - | + | ||
| - | # -------------------------------------------------- | + | |
| - | # Ensure the last alert log was not rotated too soon | + | |
| - | # -------------------------------------------------- | + | |
| if [[ -e " | if [[ -e " | ||
| CNT=`find . -name " | CNT=`find . -name " | ||
| Line 138: | Line 121: | ||
| - | # ------------------------------------------------------ | + | - |
| - | # rotate the old logs. 6->7, 5->6 etc... down until 1->2 | + | |
| - | # ------------------------------------------------------ | + | |
| i=$VERSIONS | i=$VERSIONS | ||
| while [[ $i -ge 2 ]]; do | while [[ $i -ge 2 ]]; do | ||
| Line 150: | Line 133: | ||
| done | done | ||
| - | # and finally, rotate the current log | + | - |
| cp alert_$ORACLE_SID.log alert_$ORACLE_SID.log.1 | cp alert_$ORACLE_SID.log alert_$ORACLE_SID.log.1 | ||
| [[ $? -ne 0 ]] && echo " | [[ $? -ne 0 ]] && echo " | ||
| echo > alert_$ORACLE_SID.log | echo > alert_$ORACLE_SID.log | ||
| </ | </ | ||
| + | |||
rotate_alert_logs_alertlog_with_shell_script.1544273361.txt.gz · Last modified: 2018/12/08 12:49 by 0.0.0.0
