Skip to content

Instantly share code, notes, and snippets.

@tmeissner
Last active June 1, 2020 06:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmeissner/5923615 to your computer and use it in GitHub Desktop.
Save tmeissner/5923615 to your computer and use it in GitHub Desktop.
Bash script to read out the DS18B20 1wire temp sensor. You have to modprobe the w1-gpio and w1-therm modules before using it.
#!/bin/bash
THERM=$(cat $1)
CPU=$(cat /sys/class/thermal/thermal_zone0/temp)
DATE=$(date +%Y,%m,%d%t%H,%M,%S)
echo ${THERM} | tr '\n' ' ' | grep -q "YES"
if [ $? -eq 0 ]; then
BLUB=$(echo -n ${THERM} | tr '\n' ' ' | sed "s/.*\([0-9][0-9]\)\([0-9][0-9][0-9]\).*/\1.\2/");
BLOB=$(echo -n ${CPU} | sed "s/.*\([0-9][0-9]\)\([0-9][0-9][0-9]\).*/\1.\2/");
echo "$DATE $BLUB $BLOB";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment