Skip to content

Instantly share code, notes, and snippets.

@mariushoch
Last active January 28, 2026 10:30
Show Gist options
  • Select an option

  • Save mariushoch/874371d3d49e8a3d8c54771d809cecb3 to your computer and use it in GitHub Desktop.

Select an option

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" | grep -C100 -F "$needle" | 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