This script is a Bash-based log file analyzer that provides functionality to:
- Aggregate log file data (e.g., log level counts and message frequency).
- Perform temporal analysis of log activity.
Script author: 4t0m
\(^o^)/
-
Aggregate Logs:
Analyzes log levels (trace,debug,info,warn,error,fatal) and identifies the most and least common log messages. -
Temporal Analysis:
Identifies the most active day, hour, and the hour with the highest error frequency.
./script_name.sh [Argument] <logfile>aggregate- Perform aggregation analysis of the log file.temporal_analysis- Analyze the temporal activity of logs.
-
Aggregate Analysis:
./script_name.sh aggregate example.log
Output:
=-= Aggregating file example.log =-= Log level counts: - trace: 10 - debug: 5 - info: 20 - warn: 2 - error: 1 - fatal: 0 Most common message: "User login" (count: 15) Least common message: "System rebooted" (count: 1) =-= End of report =-= ¯\_(ツ)_/¯ -
Temporal Analysis:
./script_name.sh temporal_analysis example.log
Output:
=-= example.log temporal analysis =-= Most active day: Monday Most active hour: 14 Most error-prone hour: 22 =-= End of report =-=
- Bash shell
grep,awk,sed,sort,bc,date,head,uniq,tail,cut,xargs
-
No Arguments Provided: If the script is executed without arguments:
./script_name.sh
Output:
ʕ•ᴥ•ʔ Error: No argument provided after the file. Usage: ./script_name.sh [Argument] <logfile> -
Missing Log File: If a log file is not specified:
./script_name.sh aggregate
Output:
Error: log file not specified -
Unknown Command: If an unsupported command is entered:
./script_name.sh unknown example.log
Output:
Error: Unknown command 'unknown'.
Happy analyzing!
¯_(ツ)_/¯