DEV Community

Cover image for A Practical Bash Log Analyzer for Ubuntu
Danielius Navickas
Danielius Navickas

Posted on

A Practical Bash Log Analyzer for Ubuntu

While learning Linux server administration, I wanted a practical tool that mirrors common day to day Linux support and admin tasks, quickly checking logs, spotting issues and extracting useful patterns, all without over-engineering it.

So I built a menu driven Bash log analyzer for Ubuntu systems.

What the script does
The script analyzes common Linux logs:
System logs (/var/log/syslog)

  • Show recent entries
  • Highlight errors and warnings
  • Display most frequently repeated messages
  • Supports rotated logs automatically

Authentication logs (/var/log/auth.log)

  • Recent failed login attempts
  • Most common invalid usernames
  • Top IPs responsible for failed logins
  • Works across compressed (.gz) log files

Nginx logs

  • Recent access and error entries
  • Top IPs accessing the server
  • Checks if Nginx log files exist before analyzing them

Custom log paths

  • Analyze any log file provided by the user
  • Filter for errors and warnings safely
  • All checks include basic validation to avoid crashes or noisy output.

Why I built it
This project helped me practice real admin fundamentals:

  • Reading and understanding Linux log formats
  • Using core tools effectively (grep, zgrep, awk, sort, uniq, tail)
  • Handling rotated and compressed logs
  • Writing safer and better Bash scripts (file checks, handling empty results, strict mode)
  • Structuring scripts for clarity and reuse

Challenges & fixes
A few issues I ran into and solved:
Rotated logs not being read
Switched to zcat -f and zgrep to seamlessly handle .log and .log.gz files.

"Binary file matches" errors
Fixed with -a flags to treat logs as text consistently.

Empty or misleading output
Captured results into variables and checked for empty output before printing.

Messy output
Iterated on filtering and sorting so results are readable and actionable.

What I learned

  • Bash doesn't need to be complex to be effective
  • A lot of scripts are small, focused and iterative
  • Clear output and safe handling matter more than fancy one-line code

What's next
Planned improvements:

  • Smarter error/warning filtering and sorting to show the most relevant messages first
  • Optional export to a text file
  • Show basic log rotation or size info
  • Loop back to the menu instead of exiting

The full script is here on my Github:

GitHub logo N4V1CKAS / log-analyzer

Menu-driven script to filter errors on system, auth, Nginx or custom logs on Ubuntu.

๐Ÿ“œ Log Analyzer

Quickly inspect system, authentication, Nginx or custom logs from a single interactive menu

๐Ÿ› ๏ธ Technologies

  • Bash scripting
  • Core Linux tools: grep, zgrep, awk, sort, uniq, tail, zcat

๐Ÿš€ Features

  • Analyzes common Ubuntu logs
  • Analyzes any custom log file path
  • Handles compressed logs (.gz) automatically
  • Highlights errors, warnings and failed login attempts
  • Shows top repeated log messages for quick insight
  • User-friendly interactive menu

๐Ÿ’ก Why I built it

This script was mainly created to practice Linux admin and bash scripting skills:

  • Navigating log formats and rotated logs
  • Filtering and highlighting important log messages
  • Writing safer Bash scripts with strict mode, file checks and handling empty results
  • Creating a reusable, menu-driven tool

๐Ÿ” How it works

The script prints a menu to select which log to analyze, each option prints:

  • Last few lines of the log
  • Recent errors and warnings
  • Top repeated messages or most relevant stats (failed loginsโ€ฆ

Top comments (0)