Difference between revisions of "Myth sensors.pl"

From MythTV Official Wiki
Jump to: navigation, search
(Mention locale issue)
(add refs including link to start of Perl-based script.)
Line 4: Line 4:
  
 
TODO:
 
TODO:
* This script only works when sensors is run with a specific locale.  One workaround may be to specify <code>export LANG=en_US.US-ASCII</code> at the top of the script.  Better would be to write a better script.
+
* This script only works when sensors is run with a specific locale.  One workaround may be to specify <code>export LANG=en_US.US-ASCII</code> at the top of the script.  Better would be to write a better script.  See http://www.gossamer-threads.com/lists/mythtv/dev/310925#310925 for more including the start of a more-proper Perl-based script at http://www.gossamer-threads.com/lists/mythtv/dev/311925#311925 .
  
 
{{Code box|myth_sensors.sh|
 
{{Code box|myth_sensors.sh|

Revision as of 00:55, 11 April 2010

Important.png Note: The correct title of this article is myth_sensors.pl. It appears incorrectly here due to technical restrictions.


Retrieves sensors output and formats it for inclusion in the MythTV backend status page

TODO:


Script.png myth_sensors.sh

#!/bin/bash
#
# myth_sensors.sh
# Retrieves sensors output and formats it for inclusion in the MythTV backend
# status page.

# The following line outputs information to include the CPU temperature
# information in the backend status page.  Though the sensors output includes
# the °C unit marker, it is stripped out of the data before being placed in the
# output page, so the display value includes a proper HTML entity.

#sensors | awk '/CPU Temp/ { printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", $3, $3 };'

# The following lines output CPU and Motherboard temperature and CPU and Case
# fan speed information.  Modify the patterns (i.e. /CPU Temp/) to match the
# sensors output lines containing the data you want to grab (i.e. /Core0
# Temp/).  Continue adding lines to the awk program as desired to include
# additional information.

sensors | awk '
/CPU Temp/ {
  printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", \
         $3, $3
};
/M\/B Temp/ {
  printf \
  "Current Motherboard Temperature: %s &#8451;.[]:[]temperature-MB[]:[]%s\n", \
    $3, $3
};
/CPU Fan/ {
  printf "Current CPU Fan Speed: %s.[]:[]fan-CPU[]:[]%s\n", $3, $3
};
/Case Fan/ {
  printf "Current Case Fan Speed: %s.[]:[]fan-case[]:[]%s\n", $3, $3
};
' | sort

# With appropriate authentication in place (i.e. using SSH Certificate
# Authentication), you may also retrieve sensors data from remote system (i.e.
# slave backends, remote frontends, etc.).  Do so with commands of the format
# below (provide an appropriate hostname in place of "slave" (3 places) and
# replace the awk script with one providing the desired information as shown
# above):

#ssh -q slave sensors | awk '/CPU Temp/ { printf "Current CPU Temperature (slave): %s &#8451;.[]:[]temperature-CPU-slave[]:[]%s\n", $3, $3 };'

# Alternatively, this information could be retrieved from an appropriate
# monitoring program (monit, mrtg) or by using SNMP, depending on the system
# and network configuration.