# cat /proc/meminfo | grep Mem
MemTotal: 1670688 kB
MemFree: 981140 kB
MemTotal: 1670688 kB
MemFree: 981140 kB
# cat /proc/meminfo | grep Mem
MemTotal: 2871140 kB
MemFree: 135784 kB
MemAvailable: 980380 kB
MemTotal: 2871140 kB
MemFree: 135784 kB
MemAvailable: 980380 kB
리눅스 버전 별로 나오는 내용이 다름기 때문에 계산 방법을 다르게 해야한다.
TOTAL=`cat /proc/meminfo | grep MemT | grep ^Mem | awk '{print $2}'`
USED1=`cat /proc/meminfo | grep MemF | grep ^Mem | awk '{print $2}'`
USED2=`cat /proc/meminfo | grep MemA | grep ^Mem | awk '{print $3}'`
NOMINAL=$((100*USED1/TOTAL))
ACTUAL=$((100*USED2/TOTAL))
echo NOMINAL=${NOMINAL}% ACTUAL=${ACTUAL}%
USED1=`cat /proc/meminfo | grep MemF | grep ^Mem | awk '{print $2}'`
USED2=`cat /proc/meminfo | grep MemA | grep ^Mem | awk '{print $3}'`
NOMINAL=$((100*USED1/TOTAL))
ACTUAL=$((100*USED2/TOTAL))
echo NOMINAL=${NOMINAL}% ACTUAL=${ACTUAL}%
# sh ./mem.sh
NOMINAL=4% ACTUAL=34%
NOMINAL=4% ACTUAL=34%
출처: https://developmentlee.tistory.com/163 [developmentlee]
댓글
댓글 쓰기