Skip to main content

Claude Prompt for a Log File Analyzer Script

Create a shell script that parses, analyzes, and reports on log files with pattern matching, error grouping, and anomaly detection.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt writes a Bash script that analyzes [log_type] logs at [log_path] in [log_format] over the past [time_range]. It parses timestamp, severity, component, and message with awk and sed, summarizes entries by severity with trend comparison, groups the top [top_n] error messages after normalizing variable parts like IDs and IPs, detects anomalies where a [anomaly_window]-minute window exceeds [error_threshold]x baseline, lists unique IPs cross-referenced against [blocklist_source], computes p50/p95/p99 latency over [slow_threshold] ms, and outputs both a terminal table and JSON.

The variables define what the analyzer looks at and how sensitive it is. [log_format] tells the parser how to split fields, [top_n] and [error_threshold] control how much rises to your attention, and [slow_threshold] flags slow endpoints. The error-grouping step normalizes IDs and timestamps before counting so genuinely distinct errors are not scattered across thousands of near-identical lines.

When to use it

  • A production incident starts in the logs and you need patterns fast
  • You want errors grouped by normalized pattern instead of raw line counts
  • Computing p95/p99 latency to find slowness when nothing is throwing
  • Detecting anomaly windows where error rate spikes above baseline
  • Cross-referencing request IPs against a blocklist like [blocklist_source]
  • Producing JSON output to feed a monitoring dashboard

Example output

You get a Bash script that prints a severity summary with trend, a grouped top-[top_n] error table with normalized messages and counts, flagged anomaly windows, a unique-IP list with request counts and blocklist matches, and latency percentiles highlighting endpoints over [slow_threshold] ms. The same results are written to a JSON file for dashboards. Output is dual-format: terminal table plus JSON.

Pro tips

  • Set [log_format] precisely; an awk field split that does not match your real format produces garbage counts
  • Tune [error_threshold] and [anomaly_window] to your traffic — too tight and normal bursts alert, too loose and real spikes hide
  • Trust the normalization step in error grouping; without stripping IDs and IPs, the same error appears as thousands of unique messages
  • Use the p95/p99 latency view first when something feels slow but nothing errors; averages hide the tail that users actually feel
  • Keep [blocklist_source] lookups rate-limited or cached if it is an API like AbuseIPDB, or a large unique-IP set will hit limits
  • Cap [top_n] to a readable number; you want the signal, not every rare error in one table
  • Lean on the trend comparison against the previous period; an absolute error count means little until you know whether it is higher or lower than yesterday's baseline
  • Limit the analysis to the past [time_range] so a long-lived log file does not make every run scan months of history; bounding the window keeps the script fast enough to run repeatedly during an active incident

Frequently Asked Questions

How does it avoid counting the same error thousands of times?
Before counting, it normalizes the variable parts of each message such as IDs, timestamps, and IP addresses, then groups by the normalized pattern. This collapses thousands of near-identical lines into a single grouped entry, so the top `[top_n]` list shows distinct error types rather than noise.
Can it find slow endpoints even when nothing is erroring?
Yes. It calculates p50, p95, and p99 response time percentiles where applicable and highlights endpoints exceeding `[slow_threshold]` milliseconds. This surfaces tail latency that average-based views miss, which is exactly the case where something feels slow but no errors are thrown.
What format does it output for dashboards?
It produces both a terminal-friendly table for quick human reading and a JSON file for integration with monitoring dashboards. The JSON lets you feed the analysis into other tooling, while the table is convenient during a live incident at the command line.
Does the IP blocklist check require an external service?
It cross-references unique IPs against your configured `[blocklist_source]`, which can be an API like AbuseIPDB. If you use a remote API, expect rate limits on large IP sets, so caching or limiting lookups is wise. A local blocklist file avoids that dependency entirely.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Linux & Shell Scripting Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support