I am trying to compare load average with a threshold value using shell script as i am new to it, i am able to calculate the load but the script is giving me bad number error during the condition and my condition is not working. here is my script
#!/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