A simple and fast Bash script for interactive analysis of Nginx web server logs (access.log). The script automates text data parsing using standard Linux utilities (awk, grep, sort, uniq), making it an excellent lightweight tool for system administration and basic security auditing (such as detecting anomalous traffic).
- Top 5 IP Addresses: Allows you to quickly identify the most active addresses (useful for detecting potential brute-force attacks or scrapers).
- Top 5 Routes: Shows the most popular GET requests on the server.
- Top 5 Response States: Quick monitoring of server health (e.g., tracking spikes in 404 or 500 errors).
- Top 5 User Agents: Analysis of clients, browsers, and bots accessing the resource.
- Reliability: The script uses
set -euo pipefailto protect against hidden errors, undefined variables, and pipeline failures. - Interactive Menu: A user-friendly CLI interface based on the
selectconstruct.
The script uses only standard POSIX utilities that are already pre-installed in most Linux distributions:
bashawkgrepsort,uniq,head
- Clone the repository or download the script:
git clone https://github.com/your-username/nginx-log-analyzer.git
cd nginx-log-analyzer
- Make the file executable:
chmod +x analyzer.sh
- Run the script:
./analyzer.sh
Upon launch, the script will prompt you to choose a data source:
- Enter the path to your own Nginx log file.
- Use the default test file (
nginx-access.log.txt) if it is located in the same directory.
After loading the file, an interactive menu will open:
Select 1 if you want to enter your own file and 2 if you want to test the program on a test log: 1
Enter the path: /var/log/nginx/access.log
1) Top 5 ip
2) Top 5 routes
3) Top 5 response states
4) Top 5 user agents
5) Exit
-----------------------------------------------------
Select the required functionality (1-5):
Enter the number of the desired function and press Enter to get the formatted result. To exit the program, select option 5.