SHARE
TWEET

CPU Temperature Monitor Script

cookchar Jun 4th, 2020 1,295 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Written by Charlie Cook on June 4th, 2020
  4.  
  5. # Tested on a AMD Phenom 9500; Check your own machine
  6. # by running `sensors`, and alter the awk regex
  7. # (the string between the slashes) in this script
  8. # to fit what your CPU temperature is labelled.
  9.  
  10. # (You may also need to tweak the numbers in substr(),
  11. # it works as follows; substr($N,J,K)
  12. # * N: field in the line where the temperature reading is (from 1)
  13. # * J: which character in the Nth field to start from (from 1)
  14. # * K: how many characters to take for the substring
  15.  
  16. # Check if there is a first argument and use it as the sleep delay if so
  17. if [ -z $1 ]
  18. then
  19.     s=1
  20. else
  21.     s=$1
  22. fi
  23.  
  24. # Sensor Poll counter
  25. i=6
  26.  
  27. while :
  28. do
  29.     # Get the UNIX timestamp currently to pair with our polled temp reading
  30.     t=$(date +%s)
  31.     # Poll the sensor, format the temperature with awk, append to data file
  32.     sensors -u | awk -F ":" -v t=$t '/temp1_input/ {print t,substr($2,2,4)}' >> ~/temperatureData.dat
  33.     # Determine how many graph lines to show based on number of polled readings
  34.     if (( $i < $LINES ))
  35.     then
  36.         l=$i
  37.         let "i++"
  38.     else
  39.         l=$LINES
  40.     fi
  41.     # Feed latest readings, accounting for graph title lines, to termgraph
  42.     tail -n $(( $l - 5 )) ~/temperatureData.dat | termgraph --color blue --no-labels --title "[$(hostname)] CPU Temperature (Celcius)"
  43.     # Delay before polling again
  44.     sleep $s
  45. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top