如何将负载平均值与阈值进行比较

时间:2017-12-20 17:41:46

标签: bash shell sh

我正在尝试使用shell脚本将负载平均值与阈值进行比较,因为我是新手,我能够计算负载,但脚本在条件期间给出了错误的数字错误,我的状况不起作用。这是我的剧本

#!/bin/sh

LOGFILE=/root/sy.log
WHOLEFILE=/root/sys.log


while sleep 1;
do
   TOP="$(top -n1)"
   CPU="$(cat /proc/loadavg| awk 'BEGIN{t1=t2=t3=0}{t1+=$1;t2+=$2;t3+=$3;} END {print (t1+t2+t3)/3}')"
   echo $CPU >> $LOGFILE
   CPU=`printf "%d" $CPU`
   Threshold=0.2
   Threshold=`printf "%d" $Threshold`
   if [[ "$CPU" -ge "$Threshold" ]] ;
then
       echo $TOP >> $WHOLEFILE
   fi
done

0 个答案:

没有答案