check_osx_temp.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. # Monitor temperatures in OSX
  3. # Depends on the installation of TemperatureMonitor from www.bresink.com/osx/TemperatureMonitor.html
  4. # Nagios Exit Codes
  5. OK=0
  6. WARNING=1
  7. CRITICAL=2
  8. UNKNOWN=3
  9. usage()
  10. {
  11. cat <<EOF
  12. Check the temperature sensors on OSX
  13. Options:
  14. -t Monitor tempatures
  15. -c Critical threshold in Fahrenheit
  16. Usage: $0 -t -c 180
  17. EOF
  18. }
  19. argcheck() {
  20. # if less than n argument
  21. if [ $ARGC -lt $1 ]; then
  22. echo "Missing arguments! Use \`\`-h'' for help."
  23. exit 1
  24. fi
  25. }
  26. MONITOR=0
  27. CRIT=0
  28. WARN=0
  29. COMMAND="/Applications/TemperatureMonitor.app/Contents/MacOS/tempmonitor -ds -f -a -l"
  30. ARGC=$#
  31. argcheck 1
  32. if ! [ -f /Applications/TemperatureMonitor.app/Contents/MacOS/tempmonitor ]; then
  33. echo "tempmonitor not found. Install package from www.bresink.com/osx/TemperatureMonitor.html"
  34. exit $UNKNOWN
  35. fi
  36. while getopts "htc:" OPTION
  37. do
  38. case $OPTION in
  39. h)
  40. usage
  41. ;;
  42. t)
  43. MONITOR=1
  44. ;;
  45. c)
  46. CRIT="$OPTARG"
  47. ;;
  48. w)
  49. WARN="$OPTARG"
  50. ;;
  51. \?)
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. if [ $MONITOR -eq 1 ]; then
  57. $COMMAND | sed 's/ F//' | awk -v crit=$CRIT -F : \
  58. '$2 > crit { high=1; print $0 }
  59. END {
  60. if (high == 1) {
  61. exit 2
  62. } else {
  63. exit 0
  64. }
  65. }'
  66. if [ $? -eq 2 ]; then
  67. exit $CRITICAL
  68. else
  69. echo "No high temperatures"
  70. exit $OK
  71. fi
  72. fi