cpu_temp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh -e
  2. #
  3. # cpu_temp: cpu temperature
  4. #
  5. # Copyright (C) 2008 Canonical Ltd.
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. __cpu_temp_detail() {
  22. local i
  23. for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/device/temp*_input /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal /proc/acpi/thermal_zone/*/temperature /sys/class/thermal/thermal_zone*/temp; do
  24. [ -r "$i" ] || continue
  25. printf "%s\n" "$i:"
  26. cat "$i"/*
  27. done
  28. }
  29. __cpu_temp() {
  30. local i t unit
  31. for i in $MONITORED_TEMP /sys/class/hwmon/hwmon*/device/temp*_input /sys/class/hwmon/hwmon*/temp*_input /proc/acpi/ibm/thermal /proc/acpi/thermal_zone/*/temperature /sys/class/thermal/thermal_zone*/temp; do
  32. case "$i" in
  33. *temp*_input|*thermal_zone*/temp)
  34. [ -s "$i" ] && read t < "$i" && t=$(($t/1000))
  35. ;;
  36. *)
  37. [ -s "$i" ] && t=$($BYOBU_SED -e "s/^[^0-9]\+//" -e "s/\s.*$//" "$i")
  38. ;;
  39. esac
  40. if [ -n "$t" ] && [ "$t" -gt 0 ]; then
  41. unit="$ICON_C"
  42. if [ "$TEMP" = "F" ]; then
  43. t=$(($t*9/5 + 32))
  44. unit="$ICON_F"
  45. fi
  46. color b k Y; printf "%s" "$t"; color -; color k Y; printf "%s" "$unit"; color --
  47. break
  48. fi
  49. done
  50. }
  51. # vi: syntax=sh ts=4 noexpandtab