Created
October 26, 2024 05:23
-
-
Save ronakjain2012/6b39e09bf1a45cf3f30b041809acf379 to your computer and use it in GitHub Desktop.
Script to find errors in log files using recursive method, just give the root dir and patterns separated by pipe
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
#!/bin/bash | |
root_dir="/c/testLg" | |
trap 'echo "Error processing file: $1"' ERR | |
find "$root_dir" -type f \( -name "*.log" -o -name "*.gz" \) | while read file; do | |
if [[ $file =~ \.gz$ ]]; then | |
zgrep -Eaic "connreset|error|:500" "$file" 2>null | while read count; do | |
if [[ $count -gt 0 ]]; then | |
echo "$count $file (Compressed)" | |
fi | |
done | |
else | |
grep -Eaic "connreset|error|:500" "$file" 2>null | while read count; do | |
if [[ $count -gt 0 ]]; then | |
echo "$count $file (Uncompressed)" | |
fi | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment