#!/bin/bash SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" source "$SCRIPT_DIR/lib/common-functions.sh" print_banner "Web Traffic Monitor" echo "" echo "Monitoring Apache access logs in real-time..." echo "Press Ctrl+C to exit" echo "" # Find apache log directory if [ -d "/var/log/apache2/domlogs" ]; then tail -f /var/log/apache2/domlogs/* 2>/dev/null | while read line; do ip=$(echo "$line" | awk '{print $1}') request=$(echo "$line" | awk '{print $6, $7}' | tr -d '"') status=$(echo "$line" | awk '{print $9}') # Color code by status if [[ "$status" =~ ^5 ]]; then color="\033[1;31m" # Red for 5xx elif [[ "$status" =~ ^4 ]]; then color="\033[1;33m" # Yellow for 4xx elif [[ "$status" =~ ^2 ]]; then color="\033[0;32m" # Green for 2xx else color="\033[0;37m" # White for others fi printf "${color}%-15s %s %s\033[0m\n" "$ip" "$status" "$request" done else print_error "Apache domlogs directory not found" fi