From 9f77025ffcf942789efc2e8d5eebeda16887f34b Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Mon, 13 Feb 2023 16:29:14 +0100 Subject: [PATCH] check_memory: shellfixes --- check_memory | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/check_memory b/check_memory index 3053da6..ffd3632 100755 --- a/check_memory +++ b/check_memory @@ -24,13 +24,14 @@ # 2021-03-24 v1.5 <axel.hahn@iml.unibe.ch> increase Swap critical limit 5 --> 50 # 2022-03-09 v1.6 <axel.hahn@iml.unibe.ch> show most ram intensive processes # 2022-03-10 v1.7 <axel.hahn@iml.unibe.ch> add cli param -p; update help +# 2023-02-13 v1.8 <axel.hahn@unibe.ch> shell fixes # ====================================================================== -. $(dirname $0)/inc_pluginfunctions +. "$(dirname $0)/inc_pluginfunctions" self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=1.7 +self_APPVERSION=1.8 # ---------------------------------------------------------------------- # FUNCTIONS @@ -97,30 +98,30 @@ ph.require bc # ---------------------------------------------------------------------- # set default / override from command line params -typeset -i iWarnLimit=$( ph.getValueWithParam 75 w "$@") -typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@") -typeset -i iCriticalSwap=$( ph.getValueWithParam 50 s "$@") -typeset -i iMinRamUsageToShowProcesses=$( ph.getValueWithParam 50 p "$@") +typeset -i iWarnLimit; iWarnLimit=$( ph.getValueWithParam 75 w "$@") +typeset -i iCriticalLimit; iCriticalLimit=$( ph.getValueWithParam 90 c "$@") +typeset -i iCriticalSwap; iCriticalSwap=$( ph.getValueWithParam 50 s "$@") +typeset -i iMinRamUsageToShowProcesses; iMinRamUsageToShowProcesses=$( ph.getValueWithParam 50 p "$@") # ---------------------------------------------------------------------- # read values # --- RAM -typeset -i ramTotal=$( getMemvalue MemTotal) -typeset -i ramAvail=$( getMemvalue MemAvailable) -typeset -i ramUsed=$ramTotal-$ramAvail +typeset -i ramTotal; ramTotal=$( getMemvalue MemTotal) +typeset -i ramAvail; ramAvail=$( getMemvalue MemAvailable) +typeset -i ramUsed; ramUsed=$ramTotal-$ramAvail -typeset -i ramFree=$( getMemvalue MemFree) -typeset -i ramBuffers=$( getMemvalue Buffers) -typeset -i ramCached=$( getMemvalue Cached) -typeset -i ramSReclaim=$( getMemvalue SReclaimable) +typeset -i ramFree; ramFree=$( getMemvalue MemFree) +typeset -i ramBuffers; ramBuffers=$( getMemvalue Buffers) +typeset -i ramCached; ramCached=$( getMemvalue Cached) +typeset -i ramSReclaim; ramSReclaim=$( getMemvalue SReclaimable) -typeset -i ramUsage=$(echo "($ramUsed) *100 / $ramTotal " | bc) +typeset -i ramUsage; ramUsage=$(echo "($ramUsed) *100 / $ramTotal " | bc) # --- Swap -typeset -i swapTotal=$( getMemvalue SwapTotal) -typeset -i swapFree=$( getMemvalue SwapFree) -typeset -i swapCached=$( getMemvalue SwapCached) +typeset -i swapTotal; swapTotal=$( getMemvalue SwapTotal) +typeset -i swapFree; swapFree=$( getMemvalue SwapFree) +typeset -i swapCached; swapCached=$( getMemvalue SwapCached) typeset -i swapUsage=0 if [ $swapTotal -gt 0 ]; then @@ -147,7 +148,7 @@ fi # --- show details echo -cat /proc/meminfo | egrep "^(Mem|Cache|Buffers|Swap|Slab|SReclaimable)" +grep -E "^(Mem|Cache|Buffers|Swap|Slab|SReclaimable)" "/proc/meminfo" # v1.6: show most consuming processes if usage is > nn % -- GitLab