#!/usr/bin/perl -w

my $DBHOST = "localhost";
my $DBNAME = "temperature";

use DBI;

if (exists($ARGV[1])) {
    my $id = int($ARGV[0]);
    my $method = int($ARGV[1]);

    my $sql = "SELECT action, descr FROM nattsjo_devices WHERE td_event = '$id' AND method = $method AND (TYPE = 2 OR TYPE = 0)";
    # print "$sql\n";

    my $db = DBI->connect("DBI:mysql:$DBNAME:$DBHOST", $DBUSER, $DBPASS);
    $DBI::result = $db->prepare($sql);
    $DBI::result->execute();
    while (my ($action_cmd, $descr) = $DBI::result->fetchrow_array) {
       `$action_cmd`;
       #print "$descr: $action_cmd\n\n";
    }
    undef $db;
}