Archive for December 15th, 2008
CPU Temperature Monitor Script
Sometimes in the office, i suddenly felt that my laptop is getting slower and slower. I was shocked when i looked at my conky output , that both CPU temperature is more than 80°C.
Immediately shutdown the laptop, Fix the circulation problem for CPU fan & it working normally again.
Then, i need some tool to prevent my CPU from getting burnt because of overheat. The simplest way is creating a shell script to monitor the CPU temperature and if it is exceeding predefined threshold, a shutdown command will be issued immediately.
Later, I came with this simple script.
#!/bin/sh
### Temperature Monitor
### Auto Shutdown if CPU Temperature is over threshold
### heri.cahyono@gmail.com## Define threshold for CPU Temperature
threshold=80## Get CPU Temperatur using lm-sensor
t1=`/usr/bin/sensors | nawk ‘/temp1/ {print substr($2,2,2)}’`
t2=`/usr/bin/sensors | nawk ‘/temp2/ {print substr($2,2,2)}’`if test $t1 -gt $threshold || test $t2 -gt $threshold
then
echo “CPU Temperature is exceeding threshold – Shutting down in 5 sec …….”
sleep 5
shutdown -h now
else
echo “CPU Temperature still on the safe range “
echo “Core1: $t1°C”
echo “Core2: $t2°C”
fi
The script utilize lm-sensors to detect the CPU temperature.
For Ubuntu/Debian users, it can be installed from repositories.
sudo apt-get install lm-sensors
then, configure lm-sensors to detect available sensors in the computer.
sudo sensors-detect
follow the instructions.







