Last active
December 6, 2018 14:53
-
-
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.
This file contains hidden or 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/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