如何从 ISA 适配器获取/cat CPU Core Temp?

如何从 ISA 适配器获取/cat CPU Core Temp?

我正在 Linux 中构建一个脚本来监控我的活动核心温度;

然后,当 CORE 0 TEMP 达到 40 度时,手动启用 ACPI 风扇。

为了简单起见,我已经通过在 bash 终端中输入命令来构建按需工作的 fan 脚本,它被称为 fanon。

但是我想知道如何将这个 CORE 0 临时输出 CAT 到名为 gettemp 的 bash 脚本中的变量,该变量按间隔(例如每 2 秒)更新一次。

通过使用手表传感器,我在终端中得到以下输出。

acpitz-virtual-0
Adapter: Virtual device
temp1:        +45.0°C  (crit = +256.0°C)
temp2:        +36.0°C  (crit = +105.0°C)
temp3:        +32.0°C  (crit = +105.0°C)
temp4:        +24.1°C  (crit = +105.0°C)
temp5:       +100.0°C  (crit = +110.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +41.0°C  (crit = +100.0°C) <--- This is the temp I need!
Core 1:       +38.0°C  (crit = +100.0°C) 

需要以某种方式找到 Core 0 Temp,以便我可以执行以下操作:

Core0Temp=$(cat /PATH/TO/ISA/TEMP/GOES/HERE)
Core1Temp=$(cat /PATH/TO/ISA/TEMP2/GOES/HERE)

然后我可以做

if [ $Core0Temp -gt "40" ]; then
echo "Exceeding Temp Value. Enabling Fan."
/var/tempmon/fanon
elif [ $Core0Temp -lt "40" ]; then
echo "Turning Fan Off."
/var/tempmon/fanoff
fi

如果有人想知道为什么我需要创建自己的散热机制,那只是因为我使用的是 Compaq NX-6310 商用笔记本电脑。

它(制造商)处理 ACPI 热事件的能力很差,并且与 ACPI 风扇的连接非常糟糕。谷歌上的许多搜索只向我展示了如何手动启用冷却系统。如下所示。

echo "Enabling ACPI FAN... "
echo 1 > /sys/class/thermal/cooling_device2/cur_state
echo "Fan Enabled... "

要禁用风扇,请通过 sudo 执行以下命令。

echo "Disabling ACPI FAN..."
echo 0 > /sys/class/thermal/cooling_device2/cur_state
echo "Fan Disabled..."

因此,我需要构建此脚本以使热芯片能够报告温度,并相应地启用风扇,就像您在任何沼泽标准笔记本电脑上所期望的那样。我只是找不到实际的核心温度位于哪里。手表传感器可以找到它们,但我找不到。

答案1

是的, ACPI 温度低于/sys/class/thermal,但lm_sensors硬件监控传感器低于/sys/class/hwmon/

在我的系统上, 下有三个子目录/sys/class/hwmon/hwmon0hwmon1hwmon2。就我而言,该coretemp模块恰好是hwmon1:在您的系统上这可能有所不同。您只需执行 即可识别每个子目录cat /sys/class/hwmon/hwmonN/name,其中 N 是数字。

coretemp我的系统上的温度值分别为/sys/class/hwmon/hwmon1/temp2_input/sys/class/hwmon/hwmon1/temp3_input。这些文件名上的数字tempN_input也可能与您不同,具体取决于具体的 CPU 型号。这些值将是千分之一摄氏度的整数,即 41000 将是 41.0 摄氏度。

答案2

如果您安装了 sysfs(默认情况下应该如此),您可以在 中找到临时读数/sys/class/thermal/thermal_zoneX/temp

在我的机器上,以下方法成功了

$ cat /sys/class/thermal/thermal_zone0/temp
27800
$ cat /sys/class/thermal/thermal_zone1/temp
29800
$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8°C  (crit = +105.0°C)
temp2:        +29.8°C  (crit = +105.0°C)

答案3

11小时后..它还活着!

——ACPI Thermal CPU Superscript 的诞生。


我给它起了个名字,Tempmon!


我全都明白了。

  • 我想出了如何获得临时值...
  • 我把我的发现变成了上标......

对于这个脚本来说,这是一个巨大的编码会话......

几个小时的调试和测试,但它就像一个梦......

虽然还没有完全完成,但这里和那里做了一些调整,但是它有效,而且是连续的!

  • 它检查温度,
  • 根据核心 0 温度的读数打开和关闭 ACPI 风扇,

当它回到低温时...

  • 它会在同一进程内自动重新运行!
  • 对于 tput 和 setaf,$($tput $setaf $xwhite),其颜色编码,但您可以删除这些标签并保持基本。

必须以 SUDO/ROOT 身​​份运行


我将把整个完成的脚本放在下面 - 由于它包含了如此多的命令,没有完整的东西,它不会满足我几个小时前提出的问题,如果没有完整的、完整的回答和解决我自己的问题,没有完整的代码!

此外,对于 HP 社区中的 Compaq NX-6310 商用笔记本电脑来说,此修复实际上是一个严重的错误修复!和其他人 - 也许,这种类型笔记本电脑的其他用户可能会发现这很有用,也许其他人也有类似的 ACPI 热问题,在 Linux Debian 9 中,ACPI 不会触发 ACPI 风扇本身......然后繁荣,过热 = 笔记本电脑冻结。

http://forum.notebookreview.com/threads/acpi-issues-overheating-badly-due-to-fan-not-coming-on-hp-nx6325.113746/


  # HP COMPAQ NX6310 - Reported Issue over@http://forum.notebookreview.com/threads/acpi-issues-overheating-badly-due-to-fan-not-coming-on-hp-nx6325.113746/
  #!/bin/bash
  # TEMPMON - THE CPU/ACPI THERMAL MONITORING MECHANISM 
  #FOR THE COMPAQ NX6310 ACPI-CPU-THERMAL FAN ISSUE
  #######################
  # STACK EXCHANGE QUESTION: BY SHAUN SHORTY CASSIDY.
  # https://unix.stackexchange.com/questions/418919/how-to-obtain-cat-cpu-core-temp-from-isa-adapter-debian/418935#418935
  # How to obtain/cat CPU Core Temp from ISA Adapter? - Debian
  # STATUS: SOLVED BY THIS SCRIPT.
  ######################
  # Clear the Terminal
  #-------------------------------------------------------------------------------------------------
  clear
  # Enter into script directory
  cd /var/tempmon/
  # Include Terminal Color Sheet.
  . ./style/colors
  ## Using Sed from:
  ## https://stackoverflow.com/questions/16623835/remove-a-fixed-prefix-
  suffix-from-a-string-in-bash
  ## CREATE PREFIX AND SUFFIX FOR STRING MANIPULATION.
  tempSuffix=".0°C"
  tempPrefix="+"
  ## SET UP GUI INTERFACE
  echo "$($tput $setaf $xwhite)----------------------------------------------------"
  echo "$($tput $setaf $xcyan)       tempmon | The CPU/ACPI Thermal Monitoring Script!"
  echo "$($tput $setaf $xred)----------------------------------------------------"
  ## GET THE CORE TEMPS AT SCRIPT STARTUP.
  echo "$($tput $setaf $xwhite)Getting Core 0 temp from Sensors."
  echo "$($tput $setaf $xwhite)Getting Core 1 temp from Sensors."
  echo "$($tput $setaf $xmagenta)Getting ACPI Fan Status from Sensors."
  sleep 0.1
  #-------------------------------------------------------------------------------------------------
  ## READ THE SENSORS
  Core0Temp=$(sensors | grep -i "Core 0:" | awk '{print $3}')
  Core1Temp=$(sensors | grep -i "Core 1:" | awk '{print $3}')
  ## SETUP THE ACPI FAN SENSOR
  # FAN SENSOR FILE                     
  Fan0_File="/sys/class/thermal/cooling_device2/cur_state"  
  # FAN SENSOR STATUS                       
  Fan0_Status=$(cat $Fan0_File)         
  # FAN MODULE ON                           
  Fan0_On="1"                                   
  # FAN MODULE OFF                      
  Fan0_Off="0"                          
  #-------------------------------------------------------------------------------------------------
  echo "$($tput $setaf $xred)----------------------------------------------------"                          
  echo "$($tput $setaf $xcyan)Configuring Core 0 temp into Readable Format."                                
  echo "$($tput $setaf $xwhite)Configuring Core 1 temp into Readable Format."                               
  ## CONFIGURE THE TEMPS FOR THE SCRIPTS USE.                   
  sleep 0.1                         
  Core0Temp1=$(echo "$Core0Temp" | sed -e "s/^$tempPrefix//" -e "s/$tempSuffix$//")             
  Core1Temp1=$(echo "$Core1Temp" | sed -e "s/^$tempPrefix//" -e "s/$tempSuffix$//")             
  echo "$($tput $setaf $xred)----------------------------------------------------"                          
  echo "$($tput $setaf $xcyan)Starting CPU Monitor: Core Temp 0: "$Core0Temp1""$tempSuffix                      
  echo "$($tput $setaf $xwhite)Starting CPU Monitor: Core Temp 1: "$Core1Temp1""$tempSuffix                     
  ## SET THE TEMP MARKER - STARTING TEMP                    
  ## SET THE TEMP START -  THRESHOLD TEMP               
  #-------------------------------------------------------------------------------------------------
  tempMarker="35"
  tempIDLE=$(echo $tempMarker)                                      
  tempStart="35"
  sleep 0.1
  echo "$($tput $setaf $xred)----------------------------------------------------"                          
  echo "$($tput $setaf $xwhite)Setting Initial Temp Marker @ "$tempMarker$tempSuffix                            
  echo "$($tput $setaf $xwhite)Setting Initial Temp Threshold @ "$tempStart$tempSuffix                          
  sleep 0.1                                                 
  echo "$($tput $setaf $xred)----------------------------------------------------"                          
  ## IF CPU CORE 0 TEMP IS GREATER THAN IDLE TEMP OF 35;THEN RUN LOOP..                         
  ## (HAS TO BE LOW TO TRIGGER THE LOOP)        
  #-------------------------------------------------------------------------------------------------                                #
  while true; do
  if [ $Core0Temp1 -gt $tempMarker ]; then                                  
      ## THEN NOTIFY TERMINAL THAT TEMP HAS EXCEEDED THRESHOLD TEMP                         
      echo "$($tput $setaf $xyellow)###################################################"    
      echo "$($tput $setaf $xwhite)        Exceeding Temp of: $($tput $setaf $xcyan)"$tempStart$tempSuffix                                  
      echo "$($tput $setaf $xyellow)###################################################"
      ## NOTIFY USER THAT MACHINE IS ENABLING THE ACPI FAN... (REQUIRES SUDO TO DO)                 
      echo "$($tput $setaf $xred)======================================================="   
      echo "$($tput $setaf $xcyan)--------------            Checking the ACPI Fan."                                         
      echo "$($tput $setaf $xwhite)====================================================="   
      ## THEN ENABLE THE FAN UNTIL;                                         
      ## but before enabling the fan... we must check to see if it is already active... 
      ## no point turning on a lightbulb when its already on...
      if [ $Fan0_Status -eq $Fan0_On  ]; then
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"        
        echo "$($tput $setaf $xwhite)              ERROR! --- ACPI Fan 0: Already Enabled!"
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"            
            elif [ $Fan0_Status -eq $Fan0_Off ]; then
                echo $Fan0_On > $Fan0_File      
                echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"                                    
                echo "$($tput $setaf $xwhite)             ACPI Fan 0: Enabling..."                                          
                echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
    fi
echo "----------------------------------------------------"                         
      ## Until Loop: https://stackoverflow.com/questions/29692893/read-variable-until-output-is-greater-than-a-certain-value-in-bash
  #-------------------------------------------------------------------------------------------------------------
  until [ ${Core0Temp1} -lt $tempStart ]; do                                    
      sleep 1                                                       
      ## CORE 0 TEMP RETURNS TO LESS THAN THE THRESHOLD TEMP;                               
      ## RUN EVERY SECOND                                               
      ## ON EVERY SECOND GET UPDATED TEMP VALUES                                    
      ## AND ON EVERY SECOND GET THE ACPI FAN CURRENT STATUS (SUDO NEEDED!)                     
Fan0_Status=$(cat $Fan0_File) 
    if [ $Fan0_Status -eq $Fan0_On ]; then                                      
        sleep 1
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
        echo "$($tput $setaf $xwhite)                               ACPI_FAN0 IS ENABLED"                                       
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
    elif [ $Fan0_Status -eq $Fan0_Off ]; then
        sleep 1
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
        echo "$($tput $setaf $xwhite)                               ACPI_FAN0 IS DISABLED"
        echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
    fi
Core0Temp=$(sensors | grep -i "Core 0:" | awk '{print $3}')                         
Core0Temp1=$(echo "$Core0Temp" | sed -e "s/^$tempPrefix//" -e "s/$tempSuffix$//")               
## DISPLAY THE UPDATED TEMP VALUES TO THE TERMINAL                              
echo "Core 0 Temp IS: "$Core0Temp1""$tempSuffix                                 
## THEN ALSO EVERY SECOND, RUN A CHECK TO SEE IF THE TEMP                           
## HAS RETURNED TO LESS THAN THE THRESHOLD TEMP                                 
    if [ $Core0Temp1 -lt $tempStart ]; then                                     
        ## IF THE TEMP HAS RETURNED TO LESS THAN THE THRESHOLD TEMP                         
        ## THEN DISABLE THE FAN AND NOTIFY TERMINAL                                 
        ## but again, run a check to first see if it is active.
        ## you cant turn of a light thats already off right? ;)
        ## if active then disable. if not, then dont. cause its off.
        if [ $Fan0_Status -eq $Fan0_Off  ]; then
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"                
            echo "$($tput $setaf $xwhite)/                   ERROR!                   /"
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
            echo "$($tput $setaf $xwhite)/        ACPI Fan 0: Already Disabled!       /"
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
        elif [ $Fan0_Status -eq $Fan0_On ]; then
            echo $Fan0_Off > $Fan0_File
            echo "$($tput $setaf $xcyan)###################################################"                                                                                     #
            echo "$($tput $setaf $xyellow)------------ACPI Fan 0: Disabled ./"
            echo "$($tput $setaf $xcyan)###################################################"                                                                                    #
        fi
        echo "$($tput $setaf $xwhite)###################################################"
        echo "$($tput $setaf $xcyan)--------- Core Temp Returned to: @"$tempStart""$tempSuffix
        echo "$($tput $setaf $xwhite)###################################################"
    fi
  done
  #-------------------------------------------------------------------------------------------------
  #fi   # this fi gets moved down under the return block.
  #-------------------------------------------------------------------------------------------------
  ## So what do we do if the temp is less than the predefined temp?
  ## We repeat the until function but, in a reverse order.
  ## this is so that the script runs in a kind of (>---<>---<) see saw effect...
  ## back and fourth, to and fro right.
  until [ ${Core0Temp1} -gt $tempStart ]; do                                    
   sleep 1                                                      
## CORE 0 TEMP RETURNS TO LESS THAN THE THRESHOLD TEMP;                             
## RUN EVERY SECOND                                             
## ON EVERY SECOND GET UPDATED TEMP VALUES                                  
## AND ON EVERY SECOND GET THE ACPI FAN CURRENT STATUS (SUDO NEEDED!)                       
Fan0_Status=$(cat $Fan0_File) 
    if [ $Fan0_Status -eq $Fan0_Off ]; then                                     
        sleep 1
        echo "$($tput $setaf $xwhite)/////////////////////////////////////////////"             
        echo "$($tput $setaf $xwhite)--------------------ACPI_FAN0 IS DISABLED./"
        echo "$($tput $setaf $xwhite)/////////////////////////////////////////////"             
    elif [ $Fan0_Status -eq $Fan0_On ]; then
        sleep 1
        echo "$($tput $setaf $xwhite)/////////////////////////////////////////////"             
        echo "$($tput $setaf $xwhite)--------------------ACPI_FAN0 IS ENABLED/./"
        echo "$($tput $setaf $xwhite)/////////////////////////////////////////////"             
    fi
      Core0Temp=$(sensors | grep -i "Core 0:" | awk '{print $3}')                           
      Core0Temp1=$(echo "$Core0Temp" | sed -e "s/^$tempPrefix//" -e "s/$tempSuffix$//")             
## DISPLAY THE UPDATED TEMP VALUES TO THE TERMINAL
echo "$($tput $setaf $xwhite)==============================================="                               
echo "$($tput $setaf $xwhite)           Core 0 Temp IS: "$Core0Temp1""$tempSuffix           
echo "$($tput $setaf $xwhite)==============================================="                       
## THEN ALSO EVERY SECOND, RUN A CHECK TO SEE IF THE TEMP                           
## HAS RETURNED TO LESS THAN THE THRESHOLD TEMP                                 
    if [ $Core0Temp1 -gt $tempStart ]; then                                     
        ## IF THE TEMP HAS RETURNED TO greater THAN THE THRESHOLD TEMP                          
        ## THEN ENABLE THE FAN AND NOTIFY TERMINAL                                  
        ## but again, run a check to first see if it is active.
        ## you cant turn ON a light thats already ON right? ;)
        ## if active then disable. if not, then dont. cause its off.
        if [ $Fan0_Status -eq $Fan0_On  ]; then
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"                
            echo "$($tput $setaf $xwhite)                  ERROR!                   /"
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
            echo "$($tput $setaf $xwhite)        ACPI Fan 0: Already Enabled!       /"
            echo "$($tput $setaf $xyellow)/////////////////////////////////////////////"
        elif [ $Fan0_Status -eq $Fan0_Off ]; then
            echo $Fan0_On > $Fan0_File
            echo "$($tput $setaf $xred)-------------------------------------------"                                                                                      #
            echo "$($tput $setaf $xwhite)................ACPI Fan 0: Enabled.."
            echo "$($tput $setaf $xred)-------------------------------------------"                                                                                     #
        fi
        echo "$($tput $setaf $xred)###################################################"
        echo "$($tput $setaf $xwhite)............Core Temp dropping below: @"$tempStart""$tempSuffix
        echo "$($tput $setaf $xred)###################################################"
        echo "$($tput $reset)"
    fi
  done
  #-------------------------------------------------------------------------------------------------
  fi
done
#END OF SUPERSCRIPT.

相关内容