Fix memory slot count bug in get_memory_details

The previous grep-based counting was including Size: lines from
Physical Memory Array sections, causing incorrect counts (e.g., 5/4
instead of 4/4). Now uses awk to only count Size: lines within
Memory Device sections.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-24 21:24:13 -05:00
parent d9e546f75d
commit ca23a30bd3

View File

@@ -209,8 +209,12 @@ get_memory_details() {
} }
' '
echo -e "\n${GREEN}Memory Summary:${NC}" echo -e "\n${GREEN}Memory Summary:${NC}"
echo -e " Total Slots: $(dmidecode -t memory | grep -c "Memory Device")" # Count total memory device slots (excluding Physical Memory Array entries)
echo -e " Populated: $(dmidecode -t memory | grep "Size:" | grep -cv "No Module")" local total_slots=$(dmidecode -t memory | awk '/^Memory Device$/,/^$/ {if (/Size:/) count++} END {print count}')
# Count populated slots (Size: lines with actual values, not "No Module Installed")
local populated=$(dmidecode -t memory | awk '/^Memory Device$/,/^$/ {if (/Size:/ && !/No Module/) count++} END {print count}')
echo -e " Total Slots: $total_slots"
echo -e " Populated: $populated"
echo -e " Max Capacity: $(dmidecode -t memory | grep "Maximum Capacity" | head -1 | awk '{print $3" "$4}')" echo -e " Max Capacity: $(dmidecode -t memory | grep "Maximum Capacity" | head -1 | awk '{print $3" "$4}')"
} }