This repository contains a collection of production-ready Bash scripts designed to automate log management, system monitoring, and diagnostic analysis. These projects represent my transition into DevOps engineering, focusing on shell scripting best practices, error handling, and system observability.
Across these projects, I have implemented several industry-standard scripting techniques:
Defensive Programming: Used set -euo pipefail to ensure scripts exit immediately on errors or undefined variables.
Robust File Handling: Utilized shopt -s nullglob to prevent globbing errors in empty directories.
Modular Design: Implemented reusable functions and conditional logic for system health checks.
Exit Codes: Standardized exit codes (0, 1, 2) to allow for integration with CI/CD pipelines or cron jobs.
An automated solution for log rotation and archiving. It scans a source directory for .log files and moves them to a timestamped backup location.
Features: Verification of directory existence, timestamped file versioning, and internal logging of backup activities.
Use Case: Preventing disk space issues by archiving old application logs.
A multi-file scanning tool that provides a high-level overview of log health across entire directories.
Features: Iterates through all .log files and provides a summary count of ERROR and WARNING patterns per file.
Use Case: Quick morning checks across multiple microservice logs.
Focused on deep-dive analysis of a specific application log.
Features: Calculates total line counts, identifies unique error messages using sort | uniq, and separates total vs. unique occurrences.
Use Case: Troubleshooting recurring bugs and identifying specific error spikes.
A monitoring script that evaluates log health and returns a system status based on threshold logic.
Features: Implements a "Health Check" logic.
Healthy: Minimal warnings/errors.
Warning: Exceeds 3 warnings.
Critical: Any CRITICAL pattern found or >2 errors.
Use Case: Can be used as a custom health check for a monitoring agent.
My most advanced script in the collection, combining pattern analysis with network forensics.
Features: Uses awk to extract IP addresses from error logs and identify the top offending source.
Use Case: Identifying potential security threats (brute force) or faulty client-side integrations.
Clone the repository:
git clone https://github.com/samthegent/bash-projects.git
cd bash-projects
Grant execution permissions:
Bash
chmod +x *.sh
Run a script:
Bash
./ultimate_analyzer.sh /var/log/nginx/access.log Through these projects, I strengthened my expertise in:
Stream Editors: Using grep, awk, and sed for data extraction.
Positional Parameters: Handling CLI arguments and default values ${1:-}.
Automation: Writing scripts that can be easily scheduled via crontab.
Looking to connect? Feel free to check out my other repositories or reach out on linkedin.com/in/oladimejiolalekan