ich denke meine Scripts rufe ich schon richtig auf,
Code: Alles auswählen
executeCommandLine(Duration.ofSeconds(60),"sudo","/etc/openhab/scripts/Medien_mounten.sh")
bei openhab 3 darf kein Leerzeichen im Befehl sein!
Code: Alles auswählen
executeCommandLine("sudo /etc/openhab/scripts/myscripot.sh")
geht nicht!
Beispiel von meinem sh Script um Verzeichnisse meiner externen Festplatte zu mounten
Code: Alles auswählen
#!/bin/bash
# Verzeichnis mounten, es müssen beide Verzeichnisse Vorhanden sein !
# auf /media/walter/Hd700GB/1.Media/xxxx/xxx/xxx die Originale
# auf /var/www/html/Medien/xxxx/xxxx/xxx ein Verzeichnis mit dem Namen, welches gemountet werden soll!
sudo mount --bind /media/usb_hd/hd700/1.Media/Bilder/ /var/www/html/Medien/Bilder
sudo mount --bind /media/usb_hd/hd700/1.Media/Video/ /var/www/html/Medien/Video
sudo mount --bind /media/usb_hd/hd700/1.Media/Musik/ /var/www/html/Medien/Musik
oder um Bild Dateien zu verschieben,
Code: Alles auswählen
#!/bin/bash
sudo cp -p /etc/openhab/html/bild4.jpg /etc/openhab/html/bild5.jpg
sudo cp -p /etc/openhab/html/bild3.jpg /etc/openhab/html/bild4.jpg
sudo cp -p /etc/openhab/html/bild2.jpg /etc/openhab/html/bild3.jpg
sudo cp -p /etc/openhab/html/bild1.jpg /etc/openhab/html/bild2.jpg
Für System Befehle hab ich im Habpanel ein Widget mit Auswahl: openhab reboot, Asterisk reload, Server Shutdown, Server Reboot und Verzeichnisse mounten oder umount.
das ganze noch mal mit Sicherheits Abfrage, damit nicht aus Versehen was ausgelöst wird.
Code: Alles auswählen
<!-- Schalter-7 Kachel V4 Class 2x2 -->
<div ng-if="itemValue('sysHS') == 'nixtun' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%;width:100%; font-size: 20px;"
ng-click="sendCmd('sysHS', 'oh_restart')">
openhab Restart
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%;width:100%; font-size: 20px;"
ng-click="sendCmd('sysHS', 'asterisk')">
Asterisk Reload
</button>
<button class="a button" style="top:40%;left:0%;right:0;bottom:40%;width:100%; font-size: 20px;"
ng-click="sendCmd('sysHS', 'z_reboot')">
Zotac Reboot
</button>
<button class="a button" style="top:60%;left:0%;right:0;bottom:20%;width:100%; font-size: 20px;"
ng-click="sendCmd('sysHS', 'z_shutdown')">
Zotac Shutdown
</button>
<button class="a button" style="top:80%;left:0%;right:0;bottom:0%;width:100%; font-size: 18px;"
ng-click="sendCmd('sysHS', 'z_mount')">
Verz. mounten / umount
</button>
</div>
<div ng-if="itemValue('sysHS') == 'oh_restart' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ; "
ng-click="sendCmd('System_Services', 'oh_restart')">
Openhab Restart ?
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%; font-size: 18px;
background: linear-gradient(to bottom, white, lime ) ; "
ng-click="sendCmd('sysHS', 'nixtun')">
abbrechen
</button>
</div>
<div ng-if="itemValue('sysHS') == 'asterisk' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ;"
ng-click="sendCmd('System_Services', 'asterisk_reload')">
Asterisk reload ?
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%; font-size: 18px;
background: linear-gradient(to bottom, white, lime ) ; "
ng-click="sendCmd('sysHS', 'nixtun')">
abbrechen
</button>
</div>
<div ng-if="itemValue('sysHS') == 'z_reboot' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ;"
ng-click="sendCmd('System_Services', 'z_reboot')">
Zotac Reboot ?
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%; font-size: 18px;
background: linear-gradient(to bottom, white, lime ) ; "
ng-click="sendCmd('sysHS', 'nixtun')">
abbrechen
</button>
</div>
<div ng-if="itemValue('sysHS') == 'z_shutdown' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ;"
ng-click="sendCmd('System_Services', 'z_shutdown')">
Zotac Shutdown ?
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%; font-size: 18px;
background: linear-gradient(to bottom, white, lime ) ; "
ng-click="sendCmd('sysHS', 'nixtun')">
abbrechen
</button>
</div>
<div ng-if="itemValue('sysHS') == 'z_mount' ">
<button class="a button" style="top:0%;left:0%;right:0;bottom:80%; font-size: 18px;
background: linear-gradient(to bottom, white, gray ) ;"
ng-click="sendCmd('System_Services', 'z_medien_mount')">
Medien mounten ?
</button>
<button class="a button" style="top:20%;left:0%;right:0;bottom:60%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ;"
ng-click="sendCmd('System_Services', 'z_medien_umount')">
Medien umount !
</button>
<button class="a button" style="top:40%;left:0%;right:0;bottom:40%; font-size: 18px;
background: linear-gradient(to bottom, white, gray ) ;"
ng-click="sendCmd('System_Services', 'z_download_mount')">
Download mounten ?
</button>
<button class="a button" style="top:60%;left:0%;right:0;bottom:20%; font-size: 18px;
background: linear-gradient(to bottom, white, red ) ;"
ng-click="sendCmd('System_Services', 'z_download_umount')">
Download umount !
</button>
<button class="a button" style="top:80%;left:0%;right:0;bottom:0%; font-size: 18px;
background: linear-gradient(to bottom, white, lime ) ; "
ng-click="sendCmd('sysHS', 'nixtun')">
abbrechen
</button>
</div>
und dazu die Rule
Code: Alles auswählen
rule "openhab System Befehle"
when Item System_Services changed
then
if (System_Services.state=="oh_restart") {
executeCommandLine(Duration.ofSeconds(60),"sudo","/etc/openhab/scripts/openhab.sh") // mit sh Script, geht auch !
System_Services.postUpdate("warten") // schalte Item OH_Service auf nix tun!
logInfo("OH3", "Restart")
//executeCommandLine(Duration.ofSeconds(60), "sudo","systemctl","restart","openhab") // geht auch!
}
if (System_Services.state=="asterisk_reload") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Asterisk", "reload")
executeCommandLine("sudo","/etc/openhab/scripts/asterisk.sh")
}
if (System_Services.state=="z_shutdown") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Zotac", "shutdown")
executeCommandLine(Duration.ofSeconds(60), "sudo","/sbin/poweroff")
}
if (System_Services.state=="z_reboot") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("Pause")
logInfo("Zotac", "reboot")
executeCommandLine(Duration.ofSeconds(60), "sudo","/sbin/reboot")
}
if (System_Services.state=="z_medien_mount") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Zotac Service", "z_medien_mount")
executeCommandLine(Duration.ofSeconds(60),"sudo","/etc/openhab/scripts/Medien_mounten.sh")
}
if (System_Services.state=="z_download_mount") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Zotac Service", "z_download_mount")
executeCommandLine(Duration.ofSeconds(60),"sudo","mount","--bind","/var/www/hd700/Download/","/var/www/html/Download")
}
if (System_Services.state=="z_medien_umount") {
Thread::sleep(500)
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Zotac Service", "Medien umount")
executeCommandLine(Duration.ofSeconds(60),"sudo","/etc/openhab/scripts/Medien_umount.sh")
}
if (System_Services.state=="z_download_umount") {
sysHS.postUpdate("nixtun")
System_Services.postUpdate("warten")
logInfo("Zotac Service", "Download umount")
executeCommandLine(Duration.ofSeconds(60),"sudo","umount","/var/www/html/Download")
}
end
ist jetz etwas viel Code, aber nur so kann man den Zusammenhang verstehen, denke ich.
wie man sieht sind verschiedene Wege versucht, einmal wenn mehrere Befehle sind über Script,
wenn nur ein Befehl, auch mal direkt ohne Script.