I just bought a heat sink kit for my pi and I'm using Raspbian and would like to monitor the temperature continuously every 3 seconds via SSH while I perform tasks on the pi so that I don't have to keep manually entering in a command to display the current temperature, how do I do that?
I think using watch
command is much easier, for example:
watch {your command}
In your case, it will be:
watch vcgencmd measure_temp
That will refresh by 2 seconds, if you want to define the interval by yourself (5 second maybe), you can type:
watch -n 5 <your command>
In your case, it will be:
watch -n 5 vcgencmd measure_temp
You can cancel that with Ctrl+C.
The command for viewing the current temperature is found in this post: https://raspberrypi.stackexchange.com/a/1847/22221
To automate this such that you can view the temperature every 3 seconds without entering new commands can be accomplished by writing a simple shell script that has an infinite loop:
#!/bin/bash
echo "Press [ctrl+c] to end monitoring"
echo ""
while true
do
vcgencmd measure_temp
sleep 3s
done
Place that text in a file called monitor-temp
and place it in ~/bin/
(if !/bin/
doesn't already exist, then just create it with mkdir ~/bin
). Make monitor-temp
executable: chmod 755 ~/bin/monitor-temp
. End your terminal (or ssh) session and start a new one. Now you can run monitor-temp
from any location in the file system via ssh or directly on the machine and you'll see something like the following:
pi@raspberrypi ~ $ monitor-temp
Press [ctrl+c] to end monitoring
temp=48.7'C
temp=48.7'C
temp=49.2'C
temp=49.2'C
temp=48.7'C