Skip to content

Instantly share code, notes, and snippets.

@haku
Last active August 29, 2015 14:04
Show Gist options
  • Save haku/2ffecec2c21fb2a07b4e to your computer and use it in GitHub Desktop.
Save haku/2ffecec2c21fb2a07b4e to your computer and use it in GitHub Desktop.
1wire temp mon

Tempmon

User's crontab:

HOME=/home/pi
PATH=/home/pi/bin:/usr/local/bin:/usr/bin:/bin
* * * * * /home/pi/src/tempmon/tempmon >> "/home/pi/log/tempmon.log" 2>&1
0 0 * * * mv "/home/pi/data/tempmon.txt" "/home/pi/data/tempmon_$(date +%Y%m%d).txt"

Root's crontab:

@reboot /home/pi/src/tempmon/init >> /home/pi/log/tempmon.log 2>&1
#!/bin/bash
set -eu
echo "$(date) tempmon init..."
/sbin/modprobe w1-gpio
/sbin/modprobe w1-therm
echo "$(date) done."
#!/bin/bash
set -eu
data_file="$HOME/data/tempmon.txt"
for f in /sys/bus/w1/devices/28-*/w1_slave ; do
uuid="$(echo "$f" | cut -d '/' -f '6')"
uuid="${uuid#*-}"
when="$(date +%s)"
data="$(cat "$f")"
temp="$(echo "$data" | sed -nEe 's/^.*t=([0-9]+).*$/\1/p')"
line="utime=$when uuid=$uuid temp=$temp"
echo "$line" >> "$data_file"
splunkstorm-post "$line" > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment