Skip to content

Instantly share code, notes, and snippets.

@mariushoch
Last active December 6, 2018 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariushoch/874371d3d49e8a3d8c54771d809cecb3 to your computer and use it in GitHub Desktop.
Save mariushoch/874371d3d49e8a3d8c54771d809cecb3 to your computer and use it in GitHub Desktop.
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