From cac4731e566eaa53bef8aa9d6985d224fd55bec1 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Thu, 10 Sep 2020 17:45:55 -0400 Subject: [PATCH] Cleaned up the Memory scripts by removing undeeded greps and using awk This will speed up execution because bash only needs to call the awk binary and not grep along with it. --- scripts/ram_info.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 141e7a6..90cd1f8 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -17,13 +17,13 @@ get_percent() case $(uname -s) in Linux) # percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}') - used_mem=$(free -g | grep Mem: | awk '{mem += $3} END {print mem}') - total_mem=$(free -h | grep Mem: | awk '{mem += $2} END {print mem}') + 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 | grep Mem: | awk '{mem += $3} END {print mem}') + memory_usage=$(free -m | awk '/^Mem/ {print $3}') echo $memory_usage\M\B/$total_mem\G\B else - memory_usage=$(free -g | grep Mem: | awk '{mem += $3} END {print mem}') + memory_usage=$(free -g | awk '/^Mem/ {print $3}') echo $memory_usage\G\B/$total_mem\G\B fi ;;