Fix memory capacity output parsing - was showing domain names instead of numbers

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
This commit is contained in:
cschantz
2025-12-03 01:35:43 -05:00
parent c9a94c4fbc
commit ccd4112ab7
+12 -13
View File
@@ -870,11 +870,11 @@ check_server_memory_capacity() {
echo "" echo ""
local result 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 local main_result
main_result=$(echo "$result" | tail -1) main_result=$(echo "$result" | head -1)
local total_required total_ram percentage status details local total_required total_ram percentage status details
total_required=$(echo "$main_result" | cut -d'|' -f1) total_required=$(echo "$main_result" | cut -d'|' -f1)
@@ -882,6 +882,9 @@ check_server_memory_capacity() {
percentage=$(echo "$main_result" | cut -d'|' -f3) percentage=$(echo "$main_result" | cut -d'|' -f3)
status=$(echo "$main_result" | cut -d'|' -f4) status=$(echo "$main_result" | cut -d'|' -f4)
# Get details (all lines after first)
details=$(echo "$result" | tail -n +2)
# Display summary # Display summary
cecho "${CYAN}═══════════════════════════════════════════════════════════════════${NC}" cecho "${CYAN}═══════════════════════════════════════════════════════════════════${NC}"
cecho "${WHITE}${BOLD}MEMORY CAPACITY ANALYSIS${NC}" cecho "${WHITE}${BOLD}MEMORY CAPACITY ANALYSIS${NC}"
@@ -930,17 +933,13 @@ check_server_memory_capacity() {
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}" cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
echo "" echo ""
# Get details from stderr of previous call printf "%-30s %-20s %12s %12s %12s\n" "DOMAIN" "USER" "MAX_CHILDREN" "AVG/PROCESS" "MAX_MEMORY"
local details_output printf "%-30s %-20s %12s %12s %12s\n" "------------------------------" "--------------------" "------------" "------------" "------------"
details_output=$(echo "$result" | head -n -1)
printf "%-20s %12s %12s %12s\n" "USER" "MAX_CHILDREN" "AVG/PROCESS" "MAX_MEMORY" while IFS='|' read -r domain username max_children avg_mb pool_max_mb; do
printf "%-20s %12s %12s %12s\n" "--------------------" "------------" "------------" "------------" [ -z "$domain" ] && continue
printf "%-30s %-20s %12s %12s %12s\n" "$domain" "$username" "$max_children" "$avg_mb" "$pool_max_mb"
while IFS='|' read -r username max_children avg_mb pool_max_mb; do done <<< "$details"
[ -z "$username" ] && continue
printf "%-20s %12s %12s %12s\n" "$username" "$max_children" "$avg_mb" "$pool_max_mb"
done <<< "$details_output"
echo "" echo ""
fi fi