ark/users/modules/eww/scripts/memory
2022-09-14 17:58:08 +03:00

21 lines
582 B
Bash
Executable File

#!/usr/bin/env bash
while true; do
# human-readable
freeH=$(free -h --si | rg "Mem:")
# non-human-readable
freeN=$(free --mega | rg "Mem:")
total="$(echo $freeH | awk '{ print $2 }')"
used="$(echo $freeH | awk '{ print $3 }')"
t="$(echo $freeN | awk '{ print $2 }')"
u="$(echo $freeN | awk '{ print $3 }')"
free=$(printf '%.1fG' "$(bc -l <<< "($t - $u) / 1000")")
perc=$(printf '%.1f' "$(free -m | rg Mem | awk '{print ($3/$2)*100}')")
echo '{ "total": "'"$total"'", "used": "'"$used"'", "free": "'"$free"'", "percentage": '"$perc"' }'
sleep 5
done