diff options
-rw-r--r-- | modules/mem.inc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/mem.inc b/modules/mem.inc new file mode 100644 index 0000000..9a94a17 --- /dev/null +++ b/modules/mem.inc @@ -0,0 +1,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" +} + |