#!/bin/bash
clear
# Filename for log files list
LOG_FILE_LIST="log-files-list.txt"

# Function to find and list log files
find_log_files() {
    echo "Scanning for log files from /..."
    # Use find to locate files with `.log` extension
    find / -type f -name "*.log" > "$LOG_FILE_LIST"

    if [ $? -eq 0 ]; then
        echo "Log files found and saved to $LOG_FILE_LIST."
    else
        echo "Failed to search for log files."
        exit 1
    fi
}

# Function to empty log files
empty_log_files() {
    echo "Emptying the log files listed in $LOG_FILE_LIST..."
    # Read through the log file list and empty each log file
    while IFS= read -r log_file; do
        if [ -f "$log_file" ]; then
            > "$log_file" # Empty the log file
            echo "Emptied: $log_file"
        else
            echo "Warning: $log_file does not exist or is not a file."
        fi
    done < "$LOG_FILE_LIST"
}

# Main script execution
find_log_files
empty_log_files
rm log-files-list.txt
echo "Completed processing log files."
