summaryrefslogtreecommitdiffstats
path: root/modules/mem.inc
blob: 9a94a179272aded505d30f0fc36d1e91f3879a52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/ash

# Get everything from /proc/meminfo suitable for eval to import into environment
# (Filters a few values due to invalid chars)
# With no arguments, returns everything, otherwise only those given as arguments
mem_env() {
	local a e
	if [ "$#" -eq 0 ]; then
		e='[a-zA-Z0-9]+'
	else
		# Set empty first in case a value is missing
		# TODO Within awk script (collect, check, then output)
		for a in "$@"; do
			echo "$a="
		done
		e="(${*// /|})"
	fi
	awk '{a=substr($1, 1, length($1)-1); if (a ~ /^'"$e"'$/ && $2 ~ /^[0-9]+$/) print a "=" $2}' "/proc/meminfo"
}

# Get a single entry from /proc/meminfo
mem_get() {
	awk '{if ($1 == "'"$1"':") { print $2; exit; }}' "/proc/meminfo"
}