#!/usr/bin/env bash LOG_FILE="fruit_api.log" if [[ ! -f "$LOG_FILE" ]]; then echo "❌ Log file $LOG_FILE not found!" exit 1 fi echo "📊 Fruit API Logs Report (last 2 hours) - $(date)" echo "--------------------------------------------------" # Get timestamps from last 2 hours time_filter=$(date --date='2 hours ago' +"%Y-%m-%d %H") # Show all logs from last 2 hours echo "🔹 Raw logs (last 2 hours):" grep "$time_filter" "$LOG_FILE" echo "--------------------------------------------------" echo "🔹 Status Codes Summary:" grep "$time_filter" "$LOG_FILE" | grep "RESPONSE" | awk '{print $NF}' | sort | uniq -c | sort -nr echo "--------------------------------------------------" echo "🔹 Users & IPs:" grep "$time_filter" "$LOG_FILE" | grep "REQUEST" | awk '{for(i=1;i<=NF;i++){if($i ~ /^ip=/){print $i}}}' | sort | uniq -c | sort -nr