Day 10 Task: Log Analyzer and Report Generator
Today marks the 10th day of my DevOps journey, and I delved into the powerful world of shell scripting to create a Log Analyzer and Report Generator. This script simplifies analyzing log files by counting errors, identifying critical events, and generating a comprehensive report.
Objectives:
Analyze errors in log files.
Identify critical events and print them with line numbers.
Generate a summary report in a separate text file.
Here's the shell script for this task:
Script Breakdown:
Input Validation: The script first checks if the log file provided as a command-line argument exists.
Error Count: It counts the total number of error occurrences in the log file using
awk
andwc -l
.Critical Events: It identifies lines containing "CRITICAL" and numbers them using
nl
for better readability.Summary Report: The script generates a detailed report in
report.txt
that includes the date of analysis, log file name, total lines processed, total error count, and a list of critical events with their line numbers.
Key Learnings:
Shell Scripting Proficiency: Improved my ability to write and understand shell scripts.
Text Processing: Gained insights into using
awk
for pattern matching andwc
for word/line counting.File Operations: Learned how to redirect output to files and handle file existence checks.
This task really boosted my scripting skills and highlighted how powerful shell scripts can be for automating everyday log analysis. As I progress in my DevOps journey, I'm excited to keep improving my scripting abilities and take on even more complex automation challenges.
Stay tuned for more updates as I progress through this 90-day DevOps challenge!