diff options
author | Simon Rettberg | 2019-10-28 17:27:07 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-10-28 17:27:07 +0100 |
commit | fdc1d797cdf3ebcac11df911c6ea270a96f384f8 (patch) | |
tree | e57b9652ad4c465f9f886902208d8d02d1066225 | |
parent | consider network shares in fs_path_isvolatile (diff) | |
download | slx-tools-fdc1d797cdf3ebcac11df911c6ea270a96f384f8.tar.gz slx-tools-fdc1d797cdf3ebcac11df911c6ea270a96f384f8.tar.xz slx-tools-fdc1d797cdf3ebcac11df911c6ea270a96f384f8.zip |
Add mem module
-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" +} + |