Skip to content

Instantly share code, notes, and snippets.

@discarn8
Last active January 14, 2019 07:19
Show Gist options
  • Save discarn8/cdf3557bcaa31ac089a8432c867788db to your computer and use it in GitHub Desktop.
Save discarn8/cdf3557bcaa31ac089a8432c867788db to your computer and use it in GitHub Desktop.
Raspberry_PI_CPU_GPU_TEMP_in_FAHRENHEIT_write_to_mysql
#!/bin/bash
#using: awk '{print $1/1000 * 1.8 + 32}' /sys/class/thermal/thermal_zone0/temp
CPUSOURCE=`cat /sys/class/thermal/thermal_zone0/temp`
GPUSOURCE=`vcgencmd measure_temp | cut -c 6-9`
CPUCALC=`expr $CPUSOURCE / 1000`
CPU=`echo “scale=2;((9/5) * $CPUCALC ) + 32”| bc`
GPU=`echo “scale=2;((9/5) * $GPUSOURCE ) + 32”| bc`
#Or use
#CPU=$(awk '{print $1/1000 * 1.8 + 32}' /sys/class/thermal/thermal_zone0/temp | awk '{printf("%d\n",$1 + 0.5)}')
echo CPU = $CPU
echo GPU = $GPU
#Output:
#CPU = 100.40
#GPU = 100.22
#write the temps to a table, assuming a .my.cnf is in place
/usr/bin/mysql -h 192.168.0.2 -D temp_table -e "INSERT INTO temps (ctemp, gtemp) VALUES ('$CPU','$GPU')"
@discarn8
Copy link
Author

discarn8 commented May 2, 2018

Requirements:
bc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment