Code: Alles auswählen
[11:41:08] openhabian@openHABPi:~$ uptime -p
up 1 week, 1 day, 13 hours, 26 minutes
[11:41:16] openhabian@openHABPi:~$ uptime -s
2020-07-30 22:15:07
[11:41:23] openhabian@openHABPi:~$
Code: Alles auswählen
[11:41:08] openhabian@openHABPi:~$ uptime -p
up 1 week, 1 day, 13 hours, 26 minutes
[11:41:16] openhabian@openHABPi:~$ uptime -s
2020-07-30 22:15:07
[11:41:23] openhabian@openHABPi:~$
Ah.. uptime kenne ich. Nur die Parameter dahinter nicht. Wieder etwas gelerntpeter-pan hat geschrieben: ↑8. Aug 2020 11:42 ...das auf Konsolenebene herunter zu brechen ist schon eine gute Idee. Wenn du aber vorerst mit eine "Krücke" leben kannst, damit meine ich (Neustart "openHAB" == Neustart/Reboot RasPi), dann probier mal:
Code: Alles auswählen
[11:41:08] openhabian@openHABPi:~$ uptime -p up 1 week, 1 day, 13 hours, 26 minutes [11:41:16] openhabian@openHABPi:~$ uptime -s 2020-07-30 22:15:07 [11:41:23] openhabian@openHABPi:~$
Code: Alles auswählen
[11:47:57] openhabian@openHABianPi:~$ uptime
11:50:21 up 417 days, 13:56, 1 user, load average: 1,20, 0,82, 0,77
[11:50:21] openhabian@openHABianPi:~$ uptime -p
up 1 year, 7 weeks, 4 days, 13 hours, 57 minutes
[11:50:44] openhabian@openHABianPi:~$
Code: Alles auswählen
systemd service configuration exists...
Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service
openHAB is running with PID: 2066 and has been running for 81-01:21:19
Code: Alles auswählen
sudo systemctl restart openhab2
Hallo Thomas,thomas_w hat geschrieben: ↑8. Aug 2020 08:47Im dem Output steht eigentlich zweimal der gesuchte Wert 80-06:57:25 Würde nicht einmal genügen?PeterA hat geschrieben: ↑7. Aug 2020 17:31 Bringt dann im Log:Code: Alles auswählen
BefehlOutput changed from A systemd service configuration exists... Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service openHAB is running with PID: 2066 and has been running for 80-06:57:25 to A systemd service configuration exists... Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service openHAB is running with PID: 2066 and has been running for 80-06:58:25
Der REGEX könnte so aussehen (glaub jetzt nicht, dass ich das vollständig verstanden habe, habe nur ein passendes Beispiel gefunden)Der liefert dann zweimal diesen String zurück 80-06:58:25Code: Alles auswählen
\b[\w.!#$%&’*+\/=?^`{|}~-]+-[\w-:]+(?:\.[\w-]+)*\b
Das weitere wäre dann wohl eine Formatierung im numerischen Item
REGEX ausprobieren läßt sich prima hier:
https://regexr.com/
openhab-regex-aus-text.JPG
Grüße
Thomas
Code: Alles auswählen
rule "OpenHab Uptime"
when
Item BefehlOutputOpenHabUptime changed
then
// use the transformation service to retrieve the value
val newValue = transform("REGEX", "\b[\w.!#$%&’*+\/=?^`{|}~-]+-[\w-:]+(?:\.[\w-]+)*\b", BefehlOutputOpenHabUptime.state.toString)
// post the new value to the Item
OpenHabUptime.postUpdate( newValue )
end
Code: Alles auswählen
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
Ja stimmt, das OpenHAB Regex ist nicht identisch zu den öffentlichen Regex Validatoren. Die \ müssen mit \\ escaped werden und der Befehl muss mit .* beginnen und enden.PeterA hat geschrieben: ↑8. Aug 2020 20:59 Leider meckert VSC bei dem Regex rum:Code: Alles auswählen
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
Code: Alles auswählen
// https://community.openhab.org/t/solved-help-on-regex/103231/5
// OpenHAB Regex ist nicht Standard Regex und kann nicht mit freien Validatoren verglichen werden
rule "OpenHab Uptime"
when
Item currentDateTime changed
then
// use the transformation service to retrieve the value
val BefehlOutputOpenHabUptime = "BefehlOutput changed from A systemd service configuration exists...Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB serviceopenHAB is running with PID: 2066 and has been running for 80-06:57:25 to A systemd service configuration exists...Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service openHAB is running with PID: 2066 and has been running for 80-06:58:25"
val newValue = transform("REGEX", ".*\\b[\\w.!#$%&’*+\\/=?^`{|}~-]+-[\\w-:]+(?:\\.[\\w-]+)*\\b.*", BefehlOutputOpenHabUptime )
// log das Ergebnis
logInfo('OpenHab Uptime:',newValue)
end
Code: Alles auswählen
2020-08-09 11:29:59.844 [INFO ] [.internal.RegExTransformationService] - the given regular expression '^.*\b[\w.!#$%&’*+\/=?^`{|}~-]+-[\w-:]+(?:\.[\w-]+)*\b.*$' doesn't contain a group. No content will be extracted and returned!
2020-08-09 11:29:59.850 [INFO ] [arthome.model.script.OpenHab Uptime:] -
Code: Alles auswählen
REGEX((.*))
Code: Alles auswählen
REGEX(.*eine Zeichenfolge(.*)noch eine Zeichenfolge.*)
Code: Alles auswählen
Dies ist eine Zeichenfolge und dies ist noch eine Zeichenfolge!
Oder könnte man hier:kurtharders hat geschrieben: ↑8. Aug 2020 10:24 Hallo,
um die Startzeit zu erahlten kann man die Befehlszeilenutzen. Erklärung: status mit systemctl ausgeben, mit grep die Active:-Zeile herausschneiden, mit sed die Zeichen die zwischen den Klammern stehen ausgeben lassen.Code: Alles auswählen
systemctl status openhab2 | grep running | sed 's/.*since \(.*\);.*/\1/'
Wenn man die Laufzeit genau haben will, wird es etwas komplizierter. Wenn es jemand braucht setze ich mich gerne an den awk .
Grüße, Kurt
Code: Alles auswählen
Tue 2020-05-19 10:29:17 CEST
Code: Alles auswählen
// https://community.openhab.org/t/solved-help-on-regex/103231/5
// OpenHAB Regex ist nicht Standard Regex und kann nicht mit freien Validatoren verglichen werden
rule "OpenHab Uptime"
when
Item Dummy4 changed
then
// use the transformation service to retrieve the value
val BefehlOutputOpenHabUptime = "BefehlOutput changed from A systemd service configuration exists...Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB serviceopenHAB is running with PID: 2066 and has been running for 80-06:57:25 to A systemd service configuration exists...Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service openHAB is running with PID: 2066 and has been running for 80-06:58:25"
val newValue = transform("REGEX", ".*(\\b[\\w.!#$%&’*+\\/=?^`{|}~-]+-[\\w-:]+(?:\\.[\\w-]+)*\\b).*", BefehlOutputOpenHabUptime )
// log das Ergebnis
logInfo('OpenHab Uptime:',newValue)
end
Code: Alles auswählen
2020-08-09 12:01:34.764 [INFO ] [arthome.model.script.OpenHab Uptime:] - 80-06:58:25
Code: Alles auswählen
#!/bin/bash
INPUT=$(openhab-cli status | grep -i 'running for' | tr -s ' ' | cut -d ' ' -f 12)
echo $INPUT
TEMP="A systemd service configuration exists... Use 'sudo /bin/systemctl status openhab2.service' to find the status of an openHAB service openHAB is running with PID: 4510 and has been running for 80-06:57:25"
INPUT=$(echo $TEMP | grep -i 'running for' | tr -s ' ' | cut -d ' ' -f 30)
echo $INPUT
#
# Noch ein paar alternative Tests zum Nachdenken
string="A/B/C"
#echo $string | cut -d "/" -f3
echo $string | awk -F"/" '{ print $1}'
IFS="/" read -ra ADDR <<< "${string}"; echo ${ADDR[2]}
IFS="/" read -ra ADDR <<< "${string}"; echo ${ADDR[0]}
echo ${string##*/}
testout= echo $INPUT "Tage" | awk -F "-" '{ print $1}'
echo $testout
#
# Hier noch ein Beispiel mit "if", hat aber nichts mit
# diesem Script zu tun ... nur so als Gedankenanstoss
#
# if [ -f /media/fritzbox-usb/CpuTempPi.txt ]
# then
# INPUT=$(/bin/cat /media/fritzbox-usb/CpuTempPi.txt)
# echo $INPUT
# else
# INPUT="Fritz-Box nicht gemountet"
# echo $INPUT
# fi
Code: Alles auswählen
// https://openhabforum.de/viewtopic.php?f=15&t=3855
// https://community.openhab.org/t/solved-help-on-regex/103231/5
// OpenHAB Regex ist nicht Standard Regex und kann nicht mit freien Validatoren verglichen werden
rule "OpenHab Uptime"
when
Item BefehlOutputOpenHabUptime changed
then
// use the transformation service to retrieve the value
val newValue = transform("REGEX", ".*(\\b[\\w.!#$%&’*+\\/=?^`{|}~-]+-[\\w-:]+(?:\\.[\\w-]+)*\\b).*", BefehlOutputOpenHabUptime.state.toString)
// post the new value to the Item
OpenHabUptime.postUpdate( newValue )
end