ark/users/modules/eww/scripts/memory

21 lines
582 B
Plaintext
Raw Normal View History

2022-09-14 15:35:52 +03:00
#!/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"' }'
2022-09-14 17:58:08 +03:00
sleep 5
2022-09-14 15:35:52 +03:00
done