WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to check cpu temperature with script or command  (Read 3340 times)

Offline malikawan

  • Full Member
  • ***
  • Posts: 243
    • My IP
How to check cpu temperature with script or command
« on: April 26, 2016, 12:31:30 AM »
Any way to check cpu temperature with script or command. I am using lm-sensor but it don't detect any sensor. Is there any setting after installing lm-sensor utility

Offline patrikg

  • Sr. Member
  • ****
  • Posts: 329
Re: How to check cpu temperature with script or command
« Reply #1 on: April 26, 2016, 12:54:47 AM »
How about this.
Not using lmsensor just regular linux commands.
Temp in Celsius with 2 decimals.

Code: (bash) [Select]
echo $'scale=2\n'$(cat /sys/class/thermal/thermal_zone0/temp)/1000 | bc

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10129
Re: How to check cpu temperature with script or command
« Reply #2 on: April 26, 2016, 01:29:48 AM »
Did you install the hwmon extension? Without that, you won't get cpu temp.
The only barriers that can stop you are the ones you create yourself.

Offline malikawan

  • Full Member
  • ***
  • Posts: 243
    • My IP
Re: How to check cpu temperature with script or command
« Reply #3 on: April 26, 2016, 01:30:32 AM »
its not working
cat: /sys/class/thermal/thermal_zone0/temp: No such file or directory
sh: cat:: not found

Offline malikawan

  • Full Member
  • ***
  • Posts: 243
    • My IP
Re: How to check cpu temperature with script or command
« Reply #4 on: April 26, 2016, 01:31:54 AM »
Yes curaga i have install the hwmon extension

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1703
Re: How to check cpu temperature with script or command
« Reply #5 on: April 26, 2016, 02:51:40 AM »
Quote
Is there any setting after installing lm-sensor utility

Yes, run:
Code: [Select]
sudo sensors-detect

Persistency:
Add  /etc/sysconfig/lm_sensors  to your backup.
Check  /etc/sysconfig/lm_sensors  for what modules are needed.
Load those modules in  /opt/bootlocal.sh .
For example:
Code: [Select]
modprobe coretemp
Download a copy and keep it handy: Core book ;)

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1703
Re: How to check cpu temperature with script or command
« Reply #6 on: April 26, 2016, 04:53:27 AM »
Another attempt:
Code: [Select]
#!/bin/sh
for i in /sys/class/hwmon/hwmon*
do
[ -e "$i"/temp*_label ] && LABEL="$(cat $i/temp*_label)" || LABEL="$(cat $i/name)"
TEMP="$(( $(cat $i/*_input) / 1000 ))"
echo -e "$LABEL: \t$TEMPĀ°C"
done

Download a copy and keep it handy: Core book ;)