From b2d99517d0351c5a70cba77868d40e35a6e018c4 Mon Sep 17 00:00:00 2001 From: Max Drasbeck Date: Sat, 12 Sep 2020 00:12:38 +0200 Subject: [PATCH 1/3] Added conditional for linux boxes with < 1 GB Ram --- scripts/ram_info.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 90cd1f8..431b33d 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -16,16 +16,21 @@ get_percent() { case $(uname -s) in Linux) - # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') - used_mem=$(free -g | awk '/^Mem/ {print $3}') - total_mem=$(free -h | awk '/^Mem/ {print $2}') - if (( $used_mem == 0 )); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - echo $memory_usage\M\B/$total_mem\G\B - else - memory_usage=$(free -g | awk '/^Mem/ {print $3}') - echo $memory_usage\G\B/$total_mem\G\B - fi + # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') + total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') + used_mem=$(free -g | awk '/^Mem/ {print $3}') + total_mem=$(free -h | awk '/^Mem/ {print $2}') + if (( $total_mem_gb == 0)); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') + echo $memory_usage\M\B/$total_mem_mb\M\B + elif (( $used_mem == 0 )); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + echo $memory_usage\M\B/$total_mem\G\B + else + memory_usage=$(free -g | awk '/^Mem/ {print $3}') + echo $memory_usage\G\B/$total_mem\G\B + fi ;; Darwin) From 8effb120ddf4ceb405594ae43830d54d6d266cc4 Mon Sep 17 00:00:00 2001 From: Max Drasbeck Date: Sat, 12 Sep 2020 07:25:48 +0200 Subject: [PATCH 2/3] Revert to original. --- scripts/ram_info.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 431b33d..90cd1f8 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -16,21 +16,16 @@ get_percent() { case $(uname -s) in Linux) - # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') - total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') - used_mem=$(free -g | awk '/^Mem/ {print $3}') - total_mem=$(free -h | awk '/^Mem/ {print $2}') - if (( $total_mem_gb == 0)); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') - echo $memory_usage\M\B/$total_mem_mb\M\B - elif (( $used_mem == 0 )); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - echo $memory_usage\M\B/$total_mem\G\B - else - memory_usage=$(free -g | awk '/^Mem/ {print $3}') - echo $memory_usage\G\B/$total_mem\G\B - fi + # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') + used_mem=$(free -g | awk '/^Mem/ {print $3}') + total_mem=$(free -h | awk '/^Mem/ {print $2}') + if (( $used_mem == 0 )); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + echo $memory_usage\M\B/$total_mem\G\B + else + memory_usage=$(free -g | awk '/^Mem/ {print $3}') + echo $memory_usage\G\B/$total_mem\G\B + fi ;; Darwin) From 764f267dbe4bc770a302efd42b75e4f22b2a2151 Mon Sep 17 00:00:00 2001 From: Max Drasbeck Date: Sat, 12 Sep 2020 07:27:32 +0200 Subject: [PATCH 3/3] Reintroduced fix. --- scripts/ram_info.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 90cd1f8..98d348d 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -17,9 +17,14 @@ get_percent() case $(uname -s) in Linux) # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') + total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') used_mem=$(free -g | awk '/^Mem/ {print $3}') total_mem=$(free -h | awk '/^Mem/ {print $2}') - if (( $used_mem == 0 )); then + if (( $total_mem_gb == 0)); then + memory_usage=$(free -m | awk '/^Mem/ {print $3}') + total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') + echo $memory_usage\M\B/$total_mem_mb\M\B + elif (( $used_mem == 0 )); then memory_usage=$(free -m | awk '/^Mem/ {print $3}') echo $memory_usage\M\B/$total_mem\G\B else