Skip to content

Instantly share code, notes, and snippets.

@mariushoch
Last active Dec 6, 2018
Embed
What would you like to do?
Searches MediaWiki exception.log(.gz) files for a specific exception string and prints the exception including stack trace.
#!/usr/bin/bash
if [[ "$1" == "" ]] || [[ "$2" == "" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $0 [-f] exception-log-file needle"
echo
echo "Searches exception.log(.gz) files for a specific exception string and prints the exception including stack trace."
echo "Use -f to follow newly added lines (like tail -f). Needle is case-sensitive."
exit
fi
cat=cat
if [[ "$1" == "-f" ]]; then
cat="tail -f"
shift
fi
file=$1
needle=$2
if [[ "$file" == *.gz ]]; then
cat=zcat
fi
readOn=0
$cat "$file" | while read -r line; do
if [[ ! "$line" == 20*-*-*\ *:*:* ]]; then
if [ $readOn -gt 0 ]; then
echo "$line"
fi
continue
fi
readOn=0
if [[ "$line" == *"$needle"* ]]; then
readOn=1
echo "$line"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment