Last active
March 4, 2017 00:19
-
-
Save NicholasRoge/8265011c4220141d90b4deb82dcf21f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
LOG="$DIR/../var/log/exception.log" | |
DATETIME_REGEX='\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+\-]\d{2}:\d{2}' | |
ERROR_OFFSET=0 | |
NEXT_WORD_STORE= | |
for WORD in "$@" | |
do | |
if [ -z "$NEXT_WORD_STORE" ] | |
then | |
if [[ "$WORD" == "-i" ]] | |
then | |
NEXT_WORD_STORE=ERROR_OFFSET | |
fi | |
else | |
eval $NEXT_WORD_STORE="$WORD" | |
NEXT_WORD_STORE= | |
fi | |
done | |
if [ -f "$LOG" ] | |
then | |
HEADER_LINE_NUMBERS="$(egrep -n "^${DATETIME_REGEX} ERR" "$LOG" | cut -f1 -d: | tail -n $(($ERROR_OFFSET + 1)))" | |
if [ -z "$HEADER_LINE_NUMBERS" ] | |
then | |
exit 1 | |
fi | |
if (( $ERROR_OFFSET == 0 )) | |
then | |
ERROR="$(awk "NR >= $HEADER_LINE_NUMBERS" "$LOG")" | |
else | |
START_LINE=$(echo "$HEADER_LINE_NUMBERS" | head -n 1) | |
END_LINE=$(echo "$HEADER_LINE_NUMBERS" | head -n 2 | tail -n 1) | |
ERROR="$(awk "NR >= $START_LINE && NR < $END_LINE" "$LOG")" | |
fi | |
echo "$ERROR" | head -n 2 | |
printf "\e[1;30m" | |
echo "$ERROR" | tail -n +3 | |
printf "\e[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment