FIX: Properly handle empty mysql_memory_mb in capacity calculation
The calculate_server_memory_capacity function was failing when
mysql_memory_mb was empty, causing 'integer expression expected' errors.
Now:
- Validates mysql_info is not empty before parsing
- Provides fallback '0' if cut fails
- Ensures mysql_memory_mb is always numeric
- Uses safe default comparison: ${mysql_memory_mb:-0}
This commit is contained in:
+6
-3
@@ -1006,9 +1006,12 @@ calculate_server_memory_capacity() {
|
|||||||
local mysql_status
|
local mysql_status
|
||||||
local mysql_info
|
local mysql_info
|
||||||
mysql_info=$(detect_mysql_memory_usage 2>/dev/null)
|
mysql_info=$(detect_mysql_memory_usage 2>/dev/null)
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ] && [ -n "$mysql_info" ]; then
|
||||||
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3)
|
mysql_memory_mb=$(echo "$mysql_info" | cut -d'|' -f3 || echo "0")
|
||||||
mysql_status=$(echo "$mysql_info" | cut -d'|' -f4)
|
mysql_status=$(echo "$mysql_info" | cut -d'|' -f4)
|
||||||
|
# Ensure mysql_memory_mb is numeric
|
||||||
|
mysql_memory_mb=${mysql_memory_mb:-0}
|
||||||
|
[ -z "$mysql_memory_mb" ] && mysql_memory_mb=0
|
||||||
total_required_mb=$((total_required_mb + mysql_memory_mb))
|
total_required_mb=$((total_required_mb + mysql_memory_mb))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1028,7 +1031,7 @@ calculate_server_memory_capacity() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Return formatted result - first line is summary
|
# Return formatted result - first line is summary
|
||||||
if [ "$mysql_memory_mb" -gt 0 ]; then
|
if [ "${mysql_memory_mb:-0}" -gt 0 ]; then
|
||||||
echo "$total_required_mb|$total_ram_mb|$percentage|$status|$pool_count pools|$total_max_children max_children|MySQL: ${mysql_memory_mb}MB"
|
echo "$total_required_mb|$total_ram_mb|$percentage|$status|$pool_count pools|$total_max_children max_children|MySQL: ${mysql_memory_mb}MB"
|
||||||
else
|
else
|
||||||
echo "$total_required_mb|$total_ram_mb|$percentage|$status|$pool_count pools|$total_max_children max_children"
|
echo "$total_required_mb|$total_ram_mb|$percentage|$status|$pool_count pools|$total_max_children max_children"
|
||||||
|
|||||||
Reference in New Issue
Block a user