Mindx
Mindx

Reputation: 689

when cpu temp get higher than 70 then kill process

hi im trying to make a script that help me control the temp of my cpu when i create hash files but it keep sayaing missing when it get to le process stoping here is my script

M=70
while
R1=`cat /sys/class/thermal/thermal_zone0/temp`
R2=$(($R1 / 1000))
R3=`top -bn 1 | awk 'NR>7{s+=$9} END {print s}'`
echo  "$Bl Cpu Temp $R2°C $R3$% Usage"
do
sleep 2
if [$R2 -ge $M]; then
kill -STOP 
fi
done

when i run the script it give me

Cpu Temp 62°C @ 100 % Usage

cpu.sh: 13: cpu.sh: [62: not found

Upvotes: 0

Views: 227

Answers (1)

Replace

 if [$R2 -ge $M]; then

with

 if [ "$R2" -ge "$M" ]; then

spaces are significant, because [ is really test(1) (often, a built-in variant inside your shell). Double-quotes are useful for the cases like $R2 being empty...

Read advanced bash scripting guide...

Upvotes: 3

Related Questions