Hallo,
da ich dier ersten Schritte unternehme was fhem und perl betrifft, frage ich hier mal um Hilfe.
Folgende sub-Routine habe in der Datei MyUtils.pm hinterlegt.
sub
PersonPresent($) {
my $landevice = $_[0];
my $ldnr = 0;
my $ldname = "";
my $ldstatus = "2";
Log 3, ">>> Search for lan device $landevice.";
do {
$ldname = system("/usr/bin/ssh -2 -i \~/\.ssh/id_rsa root\@192\.168\.178\.1 '/usr/bin/ctlmgr_ctl r landevice settings/landevice\"$ldnr\"/name'");
$ldnr++;
Log 3, ">>> Info $landevice $ldname $ldnr.";
} until ($ldname eq $landevice || $ldname eq "er");
$ldnr--;
if ($ldname eq "er") {
Log 1, ">>> No lan device $landevice found.";
return $ldstatus;
} else {
$ldstatus = system("/usr/bin/ssh -2 -i ~/.ssh/id_rsa root@192.168.178.1 '/usr/bin/ctlmgr_ctl r landevice settings/landevice\"$ldnr\"/active'");
Log 1, ">>> Status lan device $landevice is $ldstatus.";
return $ldstatus;
}
Log 3, ">>> Exit";
}
Die Log-Aufrufe dienen zum debuggen und verschwinden später.
Der Aufruf erfolgt wie folgt:
define CheckWalterZuHause at +*00:02 { \
use MyUtils;; \
PersonPresent('iPhone-von-Walter') \
}
attr CheckWalterZuHause room Server
attr CheckWalterZuHause alignTime 00:00
Im log erschein dann diese Information:
2013.01.02 12:44:36 3: >>> Info iPhone-von-Walter -1 57.
Wobei im Terminal-Fenster in dem ich fhem gestartet habe die ermittelten landevices ausgegeben werden.
Laut den Information, die ich mir zusammengegoogelt habe sollte nach ReturnWert = system( ... ) der Inhalt von ReturnWert das Ergebnis des system calls sein.
Kann mir hier jemand helfen?
ciao
walter
-1 ist Rückgabewert für Fehler.
Vmtl passt der Aufruf aus Deinem system()-Aufruf so nicht.
Wenn das aus telnet geht, aber aus fhem nicht, sind's meist Berechtigungsprobleme.
Läuft Dein fhem als root?
Welche Linux-Distribution auf wellcher HW ist das?
Gruß, Uli
Hallo Uli,
fhem läuft auf CentOS 6/VIA Board als root.
Mittlerweilen habe ich auch die Lösung. Folgendes habe im Internet gefunden:
Zitatsystem(): you want to execute a command and don't want to capture its output
exec: you don't want to return to the calling perl script
backticks: you want to capture the output of the command
open: you want to pipe the command (as input or output) to your script
Mit backticks funktioniert das ganze.
ciao walter