Sandbird

Quick Temp check for Pi

May 29th, 2019
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. timestamp() {
  3. date +"%Y-%m-%d %T"
  4. }
  5. LOGDIR="/var/log/fan.log"
  6. VALUE=45
  7. TEMP=`/opt/vc/bin/vcgencmd measure_temp | cut -c6,7`
  8. STATUS=`cat /sys/class/gpio/gpio2/value`
  9.  
  10. if [ -z "${STATUS}" ]; then
  11.     echo "2">/sys/class/gpio/export
  12.     echo "out">/sys/class/gpio/gpio2/direction
  13. fi
  14.  
  15. #######echo `timestamp` " Info: Temperature: $TEMP">>$LOGDIR
  16. if [ $TEMP -ge $VALUE ] && [ $STATUS -eq 0 ]
  17. then
  18. #######echo `timestamp` " Warning: Fan started.">>$LOGDIR
  19. echo "1">/sys/class/gpio/gpio2/value
  20. elif [ $TEMP -le $VALUE ] && [ $STATUS -eq 1 ]
  21. then
  22. #######echo `timestamp` " Warning: Fan stopped.">>$LOGDIR
  23. echo "0">/sys/class/gpio/gpio2/value
  24. fi
RAW Paste Data