From 42f5dcd7d9026ca59cfbff42a7684788ea73a5a6 Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 3 Dec 2025 01:35:43 -0500 Subject: [PATCH] Fix memory capacity output parsing - was showing domain names instead of numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - Output showed: 'Total Server RAM: pickledperilMB' - Output showed: 'Required if ALL pools: pickledperil.comMB' - Domain names appeared where numbers should be Root cause: - calculate_server_memory_capacity returns multiple lines: Line 1: Summary (250|1776|14|HEALTHY|...) Line 2+: Details (pickledperil.com|pickledperil|5|50MB|250MB) - Code used tail -1 to get 'last line' thinking it was summary - Actually got details line, parsed domain/username as numbers\! Fix: - Changed tail -1 to head -1 to get first line (summary) - Changed 2>&1 to 2>/dev/null to suppress stderr - Store details separately with tail -n +2 - Updated details display to include domain column (5 fields not 4) - Now shows: DOMAIN, USER, MAX_CHILDREN, AVG/PROCESS, MAX_MEMORY Result: - Numbers display correctly - Detailed breakdown shows domain → user mapping --- modules/performance/php-optimizer.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/performance/php-optimizer.sh b/modules/performance/php-optimizer.sh index 29dd805..0a5fca5 100755 --- a/modules/performance/php-optimizer.sh +++ b/modules/performance/php-optimizer.sh @@ -870,11 +870,11 @@ check_server_memory_capacity() { echo "" local result - result=$(calculate_server_memory_capacity 2>&1) + result=$(calculate_server_memory_capacity 2>/dev/null) - # Parse result (main output is last line) + # Parse result - first line is summary, remaining lines are details local main_result - main_result=$(echo "$result" | tail -1) + main_result=$(echo "$result" | head -1) local total_required total_ram percentage status details total_required=$(echo "$main_result" | cut -d'|' -f1) @@ -882,6 +882,9 @@ check_server_memory_capacity() { percentage=$(echo "$main_result" | cut -d'|' -f3) status=$(echo "$main_result" | cut -d'|' -f4) + # Get details (all lines after first) + details=$(echo "$result" | tail -n +2) + # Display summary cecho "${CYAN}═══════════════════════════════════════════════════════════════════${NC}" cecho "${WHITE}${BOLD}MEMORY CAPACITY ANALYSIS${NC}" @@ -930,17 +933,13 @@ check_server_memory_capacity() { cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}" echo "" - # Get details from stderr of previous call - local details_output - details_output=$(echo "$result" | head -n -1) + printf "%-30s %-20s %12s %12s %12s\n" "DOMAIN" "USER" "MAX_CHILDREN" "AVG/PROCESS" "MAX_MEMORY" + printf "%-30s %-20s %12s %12s %12s\n" "------------------------------" "--------------------" "------------" "------------" "------------" - printf "%-20s %12s %12s %12s\n" "USER" "MAX_CHILDREN" "AVG/PROCESS" "MAX_MEMORY" - printf "%-20s %12s %12s %12s\n" "--------------------" "------------" "------------" "------------" - - while IFS='|' read -r username max_children avg_mb pool_max_mb; do - [ -z "$username" ] && continue - printf "%-20s %12s %12s %12s\n" "$username" "$max_children" "$avg_mb" "$pool_max_mb" - done <<< "$details_output" + while IFS='|' read -r domain username max_children avg_mb pool_max_mb; do + [ -z "$domain" ] && continue + printf "%-30s %-20s %12s %12s %12s\n" "$domain" "$username" "$max_children" "$avg_mb" "$pool_max_mb" + done <<< "$details" echo "" fi