scripts/log-analyzer.sh — the single entry point for all analyses.
The script is self-contained, works on any Linux system with standard tools (grep, awk, sort, uniq), and handles both file and piped input.
Analyze /var/log/syslog with all checks:
bash
bash scripts/log-analyzer.sh -f /var/log/syslog --all
Or pipe logs directly:
bash
journalctl -u nginx --since "24 hours ago" | bash scripts/log-analyzer.sh --all
OptionDescription-f <file>Log file to analyze (use - for stdin)-p <pattern>Custom error pattern (default: error/i, fail/i, warn/i, critical/i, exception)-t <hours>Time window in hours (default: 24)--errorsFind top error messages and their frequency--time-analysisGroup errors by time period (hourly/daily)--ipsAnalyze IP frequency from log entries--spikesIdentify unusual patterns and spikes--allRun all analyses (default if no option given)--helpShow this help message
--errors)#Scans for configured error patterns, groups and sorts by frequency, shows the top most common error messages.
--time-analysis)#Groups errors into hourly and daily buckets to show when issues occur most frequently.
--ips)#Extracts IPv4 addresses from log entries, counts occurrences, and shows the top sources.
--spikes)#Compares error counts per time bucket against the average. Flags buckets that exceed 2x the average as potential anomalies.
-f - explicitly when piping-t or pre-filtering with grep