memory - scripts - various script and utils
HTML git clone git://z3bra.org/scripts
DIR Log
DIR Files
DIR Refs
---
memory (772B)
---
1 #!/bin/sh
2 #
3 # z3bra - (c) wtfpl 2014
4
5 usage () {
6 cat <<EOF
7 usage: $(basename $0) [-hptu]
8 -h : print help
9 -p : percentage of memory used (default)
10 -t : total available memory
11 -u : memory used
12 EOF
13 }
14
15 # display the total of available memory in human readable format
16 memtotal () {
17 awk '/MemTotal/{print $2*1000}' /proc/meminfo
18 }
19
20 # display the memory used
21 memused () {
22 awk '
23 /MemTotal/ {t = $2}
24 /MemFree/ {f = $2}
25 /^Buffers/ {b = $2}
26 /^Cached/ {c = $2}
27 END {print (t-f-c-b)*1000}' /proc/meminfo
28 }
29
30 # display the memory used in percentage
31 memperc () {
32 printf "%s%%\n" `echo "scale=1;100 * $(memused) / $(memtotal)" | bc`
33 }
34
35
36 case $1 in
37 -h) usage;;
38 -t) memtotal;;
39 -u) memused;;
40 *) memperc;;
41 esac