init III
This commit is contained in:
53
Perl control mFi/timer.pl
Normal file
53
Perl control mFi/timer.pl
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/perl
|
||||
## INSERT INTO `queue` (`id`, `port_id`, `state`) VALUES (NULL, '1', '1');
|
||||
|
||||
use DBI;
|
||||
use strict;
|
||||
|
||||
# Variable für SQL Befehle
|
||||
my $sql;
|
||||
|
||||
# DB Parameter
|
||||
my ($db_user, $db_name, $db_pass, $db_host) = ('1_mfi', '1_mfi', 'K01v1kk0!', 'panel.agserver.de');
|
||||
|
||||
# DB connect
|
||||
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) or die "Cannot connect to DB\n";
|
||||
|
||||
# Cron Einträge in DB?
|
||||
$sql = "select * from timer";
|
||||
my $rows = $dbh->do("$sql");
|
||||
if ($rows == 0) {
|
||||
print "nothing to do\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# Lese timer Tabelle
|
||||
$sql = "select id, min, port_id, state from timer";
|
||||
# 0 1 2 3
|
||||
my $rows = $dbh->selectall_arrayref("$sql");
|
||||
foreach (@$rows) {
|
||||
# für jeden Eintrag
|
||||
my $row=$_;
|
||||
my $id=$row->[0];
|
||||
my $min=$row->[1];
|
||||
my $port_id=$row->[2];
|
||||
my $state=$row->[3];
|
||||
|
||||
print "ID:$id Restminuten:$min Port-ID:$port_id Status:$state\n";
|
||||
|
||||
# ist 'min' = 0 eintrag löschen und einen Eintrag in queue schreiben
|
||||
if ($min == 0) {
|
||||
print "Lösche Timer und erstelle cron Eintrag\n";
|
||||
$sql = "delete from timer where id='$id'";
|
||||
$dbh->do("$sql");
|
||||
$sql = "insert into queue (port_id, state, forced, source) values ($port_id, $state, 1, 'timer')";
|
||||
$dbh->do("$sql");
|
||||
} else {
|
||||
print "Eine (weitere) Minute ist vergangen\n";
|
||||
# min um eins reduzieren
|
||||
$min--;
|
||||
# min zurückschreiben
|
||||
$sql = "update timer set min = '$min' where id='$id'";
|
||||
$dbh->do("$sql");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user