起止日期获取Alert日志内容"/>
【Shell脚本】根据起止日期获取Alert日志内容
【Shell脚本】根据起止日期获取Alert日志内容
根据输入的起止日期字符串,检索Oracle告警日志,打印中间的日志行内容。
#!/bin/bash
# $1 START_TIME_STR, e.g. "Oct 17 07:"
# $2 END_TIME_STR, e.g. "Oct 17 08:"
source /home/oracle/.bash_profile
FILEPATH="$ORACLE_BASE/diag/rdbms/`hostname`/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log"retrieveLog()
{#echo $1,$2,$3lineStart=`grep -n "$1" "$3" | awk -F":" '{print $1}' | head -n1`lineEnd=`grep -n "$2" "$3" | awk -F":" '{print $1}' | tail -n1`echo "lineStart is ${lineStart}, lineEnd is ${lineEnd}."if [ -z "${lineStart}" ] || [ -z "${lineEnd}" ]then echo "lineStart and lineEnd cannot be empty!"elseecho "Retrieving the required log ..." echo "########################################################"sed -n "${lineStart},${lineEnd}p" $3echo "########################################################"echo "Finished retrieving the required log ..."fi
}if [ -f "$FILEPATH" ]
thenretrieveLog "$1" "$2" "$FILEPATH"
elseecho "$FILEPATH does not EXIST! Please input the absolute log path."read -p "请输入日志文件路径: " LOGPATHretrieveLog "$1" "$2" "$LOGPATH"
fi
更多推荐
【Shell脚本】根据起止日期获取Alert日志内容
发布评论