S
S
sumi3sew2019-12-27 13:17:58
linux
sumi3sew, 2019-12-27 13:17:58

How to write the number of free RAM to a variable?

RAM values ​​​​can be checked by typing the free -m command, but this displays a lot of unnecessary information, how can I make sure that the value of the free RAM is displayed, so that it would be normal to write it to a variable? or is there a special method for python?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Vlad Grigoriev, 2019-12-27
@sumi3sew

It is possible through bash, it is possible on a python.
free -m | sed -n 2p | awk '{print $4}'

V
Vadim Priluzkiy, 2019-12-27
@Oxyd

free -m|grep Mem|awk '{print $4}'

V
Victor Taran, 2019-12-27
@shambler81

MEM=$(free -m | sed -n 2p | awk '{print $4}')
echo $MEM

X
xotkot, 2019-12-27
@xotkot

with a single awk
with free and awk
free -m |awk '/Mem/{print $4}'

V
Vadim Shatalov, 2019-12-27
@netpastor

https://github.com/giampaolo/psutil

R
Radjah, 2019-12-27
@Radjah

https://chtoby-pravilno.ru/chtoby/
The union "to" is always written together!

$ awk '/MemAvailable/ { memavl=$2 }; /MemTotal/ { memtot=$2 }; END {print memavl/memtot*100 } ' /proc/meminfo
62.6388

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question