#!/bin/bash # # sensors.sh # Retrieves sensors output and formats it for inclusion in the MythTV backend # status page. # The following lines output CPU and Motherboard temperature and CPU and Case # fan speed information. # # Add or remove information from the output by modifying the @output list, # below, as described in the comments. sensors | perl -w -e ' # Specify the data to retrieve and the output information in the format: # [ "", "", "" ] # Where is the label used by the sensors program for the # value you wish to include and may contain "%v" at the # location where the value should be placed. If does not # contain "%v", the value will be appended to the end. The # is an optional value for the "name" attribute, which can be used to make # machine parsing easier. my @output = ( [ "CPU Temp", "Current CPU Temperature: %v ℃", "temperature-CPU" ], [ "CPU Fan", "Current CPU Fan Speed:", "fan-CPU" ], [ "M/B Temp", "Current Motherboard Temperature: %v ℃", "temperature-MB" ], [ "Case Fan", "Current Case Fan Speed:", "fan-case" ], ); my %data = (); my ($line, $label, $display, $value, $name); while (<>) { /^(.+):\s+(?:\+|-)?(\d+\.?\d*)/; if ($1 && $2) { $data{ $1 } = $2; } } for $i (0 .. $#output) { $label = $output[$i][0]; $value = $data{$label}; if ($value) { $display = $output[$i][1]; $name = $output[$i][2]; $display = "$display %v" unless ($display =~ /%v/); $display =~ s/%v/$value/; print("${display}"); print("[]:[]${name}") if ($name); print("[]:[]${value}") if ($name && $value); print("\n"); } } '