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.
This commit is contained in:
Ethan Edwards 2020-09-10 17:45:55 -04:00
parent fbc02ca665
commit cac4731e56

View file

@ -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
;;