diff --git a/check_cpu b/check_cpu index d82a21933e6684acc5eb51f2a629fbd590924288..0f5bc3e4f38cb3fbaa21b5ee3d648717f40bac45 100755 --- a/check_cpu +++ b/check_cpu @@ -21,13 +21,14 @@ # 2022-04-14 v1.10 <axel.hahn@iml.unibe.ch> show consuming cpu processes with top and ps # 2022-08-29 v1.11 <axel.hahn@iml.unibe.ch> replace pipe to prevent start of metrics section # 2022-08-29 v1.12 <axel.hahn@iml.unibe.ch> fix: replace pipe +# 2023-02-13 v1.13 <axel.hahn@iml.unibe.ch> small shell fixes # ====================================================================== . $(dirname $0)/inc_pluginfunctions self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=1.12 +self_APPVERSION=1.13 # ---------------------------------------------------------------------- # functions @@ -114,7 +115,7 @@ typeset -i iMinCpuUsageToShowProcesses=$( ph.getValueWithParam 50 p "$@") # top -b -n 1 | head -5 | grep "^\%Cpu" >$tmpfile # FIX read cpu from 2nd output of top -data=$( top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 | cut -f 2- -d ':' | tr ',' "\n" ) +data=$( top -b -n 2 -d 0.1 | grep -i "^%Cpu" | tail -1 | cut -f 2- -d ':' | tr ',' "\n" ) cpuUser=$( echo "$data" | grep "us" | awk '{ print $1 }' ) cpuSystem=$( echo "$data" | grep "sy" | awk '{ print $1 }' ) @@ -160,14 +161,17 @@ echo "$plist" | grep "[0-9]" >/dev/null \ && echo "$plist" | tr '|' ':' # v1.7: show most consuming processes if usage is > nn % -typeset -i iUsed=$( echo $cpuNonIdle | cut -f 1 -d '.' ) +typeset -i iUsed +iUsed=$( echo $cpuNonIdle | cut -f 1 -d '.' ) if [ $iUsed -gt $iMinCpuUsageToShowProcesses ]; then echo echo "CPU usage is higher $iMinCpuUsageToShowProcesses percent ... showing most consuming processes" echo "output of top :" topout=$( top -b -n 1 -d 0.1 ) - typeset -i iStart=$( echo "$topout" | grep -n "PID.*USER" | cut -f 1 -d ':' ) - typeset -i iEnd=$iStart+5 + typeset -i iStart + iStart=$( echo "$topout" | grep -n "PID.*USER" | cut -f 1 -d ':' ) + typeset -i iEnd + iEnd=$iStart+5 echo "$topout" | sed -n "${iStart},${iEnd}p" | tr '|' ':' echo echo "output of ps:"