Wednesday, 14 January 2009

Tip of the Day: Use lm-sensors to Monitor Your Hardware

sensors is a tool which will output the temperatures read from all your chip sensors. To get this utility, you will have to install the lm-sensors package. In Debian Lenny, issue the following command as root:

apt-get install lm-sensors

This package contains the sensors tool, which if ran will output voltages and temperatures for your CPU, graphics card, and so on.

Next, we will make a simple script which will trigger sensors every five seconds, so you will be able to monitor your system in different load times:

#!/bin/bash

i=0
while [[ 1 -eq 1 ]]; do
clear
echo "Running sensors..."
echo -e "Elapsed time: $i seconds\n"
sensors
echo "Use ^C (CTRL+C) to stop"
sleep 5
i=$(( $i + 5 ))
done

This script will run the sensors utility every five seconds. You can save it under a suggestive name,
say cputemp.sh, make it executable (chmod 755 cputemp.sh) and put it in a directory in your path
(e.g. ~/bin/, where ~ is your home directory).

2 comments:

dwave said...

Instead of a looping bash script I'd recommend the command 'watch' that could be quite useful as it is especially tailored for cases like this one here.
The command 'watch' provides an easy way to run commands repeatedly and to display their output in a very nice way similiar to top/htop. Check out its command line parameters:
-n, --interval=[seconds] specifies the interval in seconds
-d, --differences[=cumulative] highlights the differences between intervals

Dan Craciun said...

Thanks for the suggestion, it works very well too.