1Wire implementation
Min crontab som anropar alla scripts ser ut så här:
root@slug:~# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.8342 installed on Sun Sep  7 17:05:36 2008)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# (Use to post in the top of your crontab)
# ----------------- minute (0 - 59)
# |  -------------- hour (0 - 23)
# |  |  ----------- day of month (1 - 31)
# |  |  |  -------- month (1 - 12)
# |  |  |  |  ----- day of week (0 - 7) (Sunday=0 or 7)
# |  |  |  |  |
# *  *  *  *  *  command to be executed
MAILTO=""
*/2 * * * * /usr/bin/get_torrents.sh
*/5 * * * * /usr/bin/burner_status.pl
#*/3 * * * * /pub/src/ow4roku.pl
* * * * * /usr/bin/update_rrd_files
* * * * * /pub/rrd/gen_smoke_stat.pl
13 * * * * /usr/bin/upload_rrd_plots -24h
42 0 * * * /usr/bin/upload_rrd_plots -1w

RRD-databaserna skapade jag med:
#!/bin/sh

# 1min interval, if no data for 600sec set to unknown
# 10080 * 1 min = 7 dagar med minutvärden
# 4680 * 10 min = 32 dagar med 10min värden AVERAGE
# 8760 * 1h = 365 dagar med 1h värden AVERAGE, MIN and MAX
# 3650 * 1d = 10 år med 1 dagsvärden AVERAGE, MIN, MAX

RRDs="stigare inne ute rokgas"

RRDBASE=/pub/rrd
for i in $RRDs
do
echo Creating $RRDBASE/$i.rrd
/opt/bin/rrdtool create $RRDBASE/$i.rrd --step 60 DS:temp:GAUGE:600:-270:1370 RRA:AVERAGE:0.5:1:10080 RRA:AVERAGE:0.5:10:4680 RRA:MIN:0.5:60:8760 RRA:MAX:0.5:60:8760 RRA:AVERAGE:0.5:1440:3650 RRA:MIN:0.5:1440:3650 RRA:MAX:0.5:1440:3650
chmod 644 $RRDBASE/$i.rrd
done


Mitt bash-scripts som varje minut anropas av cron, läser av sensorer och uppdaterar rrd-databaserna:
#!/bin/sh

SENSORS="
/tmp/1wire/bus.0/10.627F7C010800/temperature:stigare.rrd
/tmp/1wire/bus.0/10.29877C010800/temperature:ute.rrd
/tmp/1wire/bus.0/10.057C7C010800/temperature:inne.rrd
/tmp/1wire/bus.0/30.FFDF61120000/typeK/temperature:rokgas.rrd
"

RRDBASE=/pub/rrd

for SENSOR_INFO in $SENSORS
do
SENSOR=`expr $SENSOR_INFO : '\(.*\):'`
RRDFILE=`expr $SENSOR_INFO : '.*:\(.*\)'`
if [ "$SENSOR" != "" ]; then
VALUE=""
echo -n "Reading $SENSOR "
i=0
while [ $i -lt 4 ]
do
VALUE=`cat $SENSOR | tr -d ' '`
if [ "$VALUE" != "125" ]; then
break
else
echo -n "r"
fi
let i+=1
sleep 1
done

VALUE_OK=""
echo -n "got '$VALUE'"
if [ "$VALUE" = "125" ]; then
echo -n " Bad value"
else
if [ "$VALUE" = "" ]; then
echo -n " Empty value"
else
VALUE_OK=$VALUE
fi
fi

if [ "$RRDFILE" != "" ]; then
if [ "$VALUE_OK" != "" ]; then
echo -n " Adding to RRD file $RRDFILE"
/opt/bin/rrdtool update $RRDBASE/$RRDFILE N:$VALUE_OK
fi
fi
else
echo -n "Unable to extract SENSOR from $SENSOR_INFO"
fi
echo
done

Bash-scriptet upload_rrd_plots som också anropas av cron såklart är ansvarigt för att generera grafer och ftp:a upp dom till mitt webb-hotell:
#!/bin/sh

cd /pub/rrd

./gen_graphs.pl -s $1

./upload.pl

Perl-scriptet gen_graphs.pl ser ut så här:
#!/opt/bin/perl
use lib '/pub/rrd/lib';
use OwfsSensors;
use Getopt::Std;
getopt('st');
use RRDp;
RRDp::start "/opt/bin/rrdtool";

@sensors = OwfsSensors::names();

foreach $s (@sensors) {
  my $rrd  = "$s.rrd";
  my $temp = OwfsSensors::temp($s);
  $com = "Genererad\\: ";
  $com .= `date +%F | sed 's/\:/\\\\:/g'`;
  $com .= "vid ".`date +%T | sed 's/\:/\\\\:/g'`;

  chop $com;
  $com .= "\, aktuell temperatur $temp" . "C";
  $starttime = "$opt_s";
  $endtime   = time;
  $title     = "\U".$s."temperatur";
  $width     = "600";
  $height    = "400";

  RRDp::cmd "graph graphs/$s$opt_s.png --imgformat PNG --start '$starttime' --end
  '$endtime' --width $width --height $height -E --title '$title'
  --vertical-label
  'Celsius' -l 0",
          "DEF:".$s."temp=$rrd:temp:AVERAGE",
          "LINE2:".$s."temp#FF0000",
#          "GPRINT:".$s."temp:LAST:\"%d\\n\"",
          "COMMENT:\"$com\"";
  $answer=RRDp::read;

  print $$answer;
}

RRDp::end;

Och upload.pl så här:
#!/opt/bin/perl

use Net::FTP;

# First we must create the html file
system("/pub/rrd/create_html.pl");

my @txts =
  ("tmp/index.html", "tmp/temp24h.html", "tmp/temp1w.html", "smoke_stat.txt");

my @graphs =
  ("ute-24h.png", "stigare-24h.png", "inne-24h.png", "rokgas-24h.png",
   "ute-1w.png",  "stigare-1w.png",  "inne-1w.png",  "rokgas-1w.png");

$ftp = Net::FTP->new("ftp-sajt")     or die "Can't connect: $@\n";
$ftp->login("ftp-username", "Hemligt lösen")      or die "Couldn't login\n";
$ftp->cwd("rrd")                        or die "Couldn't change dir to rrd\n";

$ftp->ascii();
foreach $t (@txts) {
  $ftp->put($t)                         or die "Couldn't upload $t\n";
}

$ftp->binary();
foreach $g (@graphs) {
  $ftp->put("graphs/" . $g)             or die "Couldn't upload graphs/$g\n";
}

$ftp->quit();