fan_speed 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh -e
  2. #
  3. # fan_speed: speed of the cpu or case fan
  4. #
  5. # Copyright (C) 2009 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. __fan_speed_detail() {
  22. # Nothing interesting to say here about fan speed
  23. return
  24. }
  25. __fan_speed() {
  26. local i="" speed=0
  27. # Let's check a few different probes for fan speed
  28. # This seems to cover most of them:
  29. for i in $FAN /sys/class/hwmon/*/*/fan1_input /sys/class/hwmon/*/device/hwmon/*/fan1_input; do
  30. [ -f "$i" ] || continue
  31. read speed < "$i"
  32. if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
  33. color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
  34. return 0
  35. fi
  36. done
  37. # But others (e.g. Dell Inspirons) seem to be here:
  38. if [ -r /proc/i8k ]; then
  39. local line=""
  40. read line < /proc/i8k
  41. set -- $line
  42. for speed in $7 $8; do
  43. if [ -n "$speed" ] && [ "$speed" -gt 0 ]; then
  44. # I8K_FAN_MULT defaults to 30 (buggy BIOS workaround?),
  45. # use `modprobe i8k fan_mult=1` to disable if unneeded,
  46. # resulting in nonsensical speeds
  47. [ "$speed" -gt 10000 ] && speed=$((${speed} / 30))
  48. color bold1; printf "%s" "$speed"; color -; color none; printf "rpm"; color --
  49. return 0
  50. fi
  51. done
  52. fi
  53. }
  54. # vi: syntax=sh ts=4 noexpandtab