#!/bin/bash

# Determine base directory path
BASE_DIR="/var/www/html"
if [ ! -d "$BASE_DIR" ]; then
    BASE_DIR="/var/www/html"
fi

# Target directories to check for logs
TARGET_DIRS=("$BASE_DIR/public/logdata" "$BASE_DIR/public" "$BASE_DIR/volumes/logdata")

echo "$(date): Checking for logs exceeding 100MB..."

for dir in "${TARGET_DIRS[@]}"; do
    if [ -d "$dir" ]; then
        find "$dir" -maxdepth 2 -name "*.log" -type f -size +100M | while read -r logfile; do
            echo "Log file $logfile is larger than 100MB. Truncating to 0..."
            truncate -s 0 "$logfile"
        done
    fi
done

echo "$(date): Clean-up check complete."
