Coloring alert.log output via tail and less
Making my day to day job easier and convenient I like having some utilities and some aliases.
We, the DBAs nation, have a need to look at the alert.log file frequently. So basically, I did the following:- Created a script to tail my alert.log file.
- Colored the important words.
- Added an alias to that script
$ vi tail_alert.sh
#!/bin/bash
export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${SCRIPT_DIR}/platform.env
ECHO_RED="\E[1;40;31m"
ECHO_STD="\E[1;40;37m"
LIGHT_RED=`echo -e '\033[1;40m\033[1;31m'`
RED=`echo -e '\033[1;40m\033[0;31m'`
LIGHT_PURPLE=`echo -e '\033[1;40m\033[0;35m'`
GREEN=`echo -e '\033[1;40m\033[32m'`
NORMAL=`echo -e '\033[0m'`
if [ "$1" = "" ]
then
ALERT_FILE=${ORACLE_BASE}/diag/${DIR_TYPE}/${ORACLE_UNQNAME,,}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log
if [ ! -s ${ALERT_FILE} ]
then
echo
echo -e "${ECHO_RED}please provide alert.log file name${ECHO_STD}"
echo
exit
fi
else
ALERT_FILE="$1"
fi
WARNING_PATTERN="ORA-\|annot\| not\|WARNING\|cannot allocate\|not complete\|LGWR: Attempting destination\|network reconnect\|LGWR: Destination LOG_ARCHIVE_DEST_\|is UNSYNCHRONIZED\|All online logs need archiving\|Examine archive trace files for archiving errors\|hung\|Killing\|Terminating\|WARN:\|Possible network disconnect\|Archive log rejected\|request rejected\|dead\|failed\|shutting down\|shutdown\|disabled"
ERROR_PATTERN="ORA-[^:][^ ]*\|TNS-[^:][^ ]*\|Error\|Archival stopped\|Fatal"
GOOD_PATTERN="continu\|STARTING\|Completed:\|COMPLETE\|Starting ORACLE instance\|Success\|succeeded"
tail -n30 -f ${ALERT_FILE} | ${SED} "s/${WARNING_PATTERN}/${LIGHT_PURPLE}&${NORMAL}/gi;s/${ERROR_PATTERN}/${LIGHT_RED}&${NORMAL}/gi;s/${GOOD_PATTERN}/${GREEN}&${NORMAL}/gi"
The last step to make it the easiest way to run, is adding an alias to the script
alias talert='/home/oracle/scripts/tail_alert.sh'The same trick for just viewing the file via less
$ vi less_alert.shAnd again adding an alias to the script
#!/bin/bash
export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${SCRIPT_DIR}/platform.env
ECHO_RED="\E[1;40;31m"
ECHO_STD="\E[1;40;37m"
LIGHT_RED=`echo -e '\033[1;40m\033[1;31m'`
RED=`echo -e '\033[1;40m\033[0;31m'`
LIGHT_PURPLE=`echo -e '\033[1;40m\033[0;35m'`
GREEN=`echo -e '\033[1;40m\033[32m'`
NORMAL=`echo -e '\033[0m'`
if [ "$1" = "" ]
then
ALERT_FILE=${ORACLE_BASE}/diag/${DIR_TYPE}/${ORACLE_UNQNAME,,}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log
if [ ! -s ${ALERT_FILE} ]
then
echo
echo -e "${ECHO_RED}please provide alert.log file name${ECHO_STD}"
echo
exit
fi
else
ALERT_FILE="$1"
fi
WARNING_PATTERN="ORA-\|annot\| not\|WARNING\|cannot allocate\|not complete\|LGWR: Attempting destination\|network reconnect\|LGWR: Destination LOG_ARCHIVE_DEST_\|is UNSYNCHRONIZED\|All online logs need archiving\|Examine archive trace files for archiving errors\|hung\|Killing\|Terminating\|WARN:\|Possible network disconnect\|Archive log rejected\|request rejected\|dead\|failed\|shutting down\|shutdown\|disabled"
ERROR_PATTERN="ORA-[^:][^ ]*\|TNS-[^:][^ ]*\|Error\|Archival stopped\|Fatal"
GOOD_PATTERN="continu\|STARTING\|Completed:\|COMPLETE\|Starting ORACLE instance\|Success\|succeeded"
cat ${ALERT_FILE} | ${SED} "s/${WARNING_PATTERN}/${LIGHT_PURPLE}&${NORMAL}/gi;s/${ERROR_PATTERN}/${LIGHT_RED}&${NORMAL}/gi;s/${GOOD_PATTERN}/${GREEN}&${NORMAL}/gi" | less -R
alias alert='/home/oracle/scripts/less_alert.sh'Sample output:
Enjoy
Comments
Post a Comment