Coloring the Oracle Alert Log

echo ‘export TERM=xterm-256color’ >> ~/.bashrc

echo ‘export TERM=xterm-mono’ >> ~/.bashrc

https://www.cyberciti.biz/faq/turn-off-color-in-linux-terminal-bash-session/

$ vi less_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"

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

And again adding an alias to the script

alias alert=’/home/oracle/scripts/less_alert.sh’

https://oracledba.blogspot.com/2018/01/coloring-alertlog-output-via-tail-and.html

https://unix.stackexchange.com/questions/8414/how-to-have-tail-f-show-colored-output

https://automationrhapsody.com/coloured-log-files-linux/

 

https://unix.stackexchange.com/questions/408867/how-to-colorize-some-of-the-output-of-a-shell-script

https://linoxide.com/how-tos/change-linux-shell-prompt-with-different-colors/

 

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Google photo

您的留言將使用 Google 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s