CahBojonegoro

Rawe Rawe Rantas, Malang Malang Putung

CPU Temperature Monitor Script

with one comment

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.

Advertisements

Written by cahbojonegoro

December 15, 2008 at 3:26 pm

Posted in Ubuntu, Unix

One Response

Subscribe to comments with RSS.

  1. doesn’t work on Ubuntu Desktop 16.04

    Yevgeniy Must

    February 20, 2017 at 4:25 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: