Skip to content

Instantly share code, notes, and snippets.

@ronakjain2012
Created October 26, 2024 05:23
Show Gist options
  • Save ronakjain2012/6b39e09bf1a45cf3f30b041809acf379 to your computer and use it in GitHub Desktop.
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
#!/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