Access folder in /etc/openhab for showing events.log and openhab.log in sitemap


i wrote the following script for getting my logs openhab.log and events.log in my sitemap to view the last 200 log lines. therefore I created the folder webapps/weblogs in /etc/openhab2 and used this script:

#!/bin/bash tac /var/logs/openhab2/events.log | head -n 200 > /etc/openhab2/webapps/weblogs/events.log tac /var/logs/openhab2/openhab.log | head -n 200 > /etc/openhab2/webapps/weblogs/openhab.log date +"%d.%m.%Y %T"

on my item:

String st_copyLogs {exec="<[/etc/openhab2/scripts/*?))]"}

and finally I try to get the data shown in my sitemap, but I have problems to access:

Frame label=“Logfiles” {
Text item=st_copyLogs label=“openhab.log [%s]” icon=“settings” {
Webview url=“https://192.168.1.x:8443/weblogs/openhab.log” height=20
Text item=st_copyLogs label=“events.log [%s]” icon=“settings” {
Webview url=“https://192.168.1.x:8443/weblogs/events.log” height=20

Problem: how can I access my /etc/openhab2/webapp/weblogs folder ? Where do I have to config this and how?
thanks in advance…

Put your files and directories into /etc/openhab2/html/ ( e.g. /etc/openhab2/html/YourFile.txt. Then you can access them via https://your.domain/static/YourFile.txt

Btw. shouldn’t it be tail -n 200 ( last 200 rows ) instead of head -n 200 ( first 200 rows ) ?

Ok this works. See man tac. It makes reverse order. One question: per click my script is not called… Where can I set up that a click in my sitemap calls the script and after that shows it?

Another way :slight_smile:

sounds like two actions need to be done one after an other:

  • run the script to create the log that is to be displayed
  • display the content of the files
    may be this could be done with async. javascript ( I am not an expert for that )

What about using the exec binding which returns the output of the head command into a variable that will be displayed ? I am not sure if multiple lines can be returned in to a string and how many characters can be loaded into a string.

Are there exists any standard mechanism for starting a script per click in openhab2 ?
my item definition should make this:

String st_copyLogs {exec="<[/etc/openhab2/scripts/*?))]"}

but it does not work ?

That’s syntax of the exec V1 binding.
Did you try exec V2 binding ?
As far as I understand the functionality your script will be executed every 60 seconds and should update the content of st_copyLogs.
Can you check if it is executed every 60 seconds ( e.g. by using date >> /tmp/tmp.txt in your shell script ) ? It could be that the string returned is too long to be handled e.g. return the current date time to see that the content is updated every 60 seconds.

hi, i have in the log the last statements from events.log the script is never called… I tried to start from shell and set up the rights to user/group openhab:openhab, with full access 777 but still does not work.
can you give me the syntax of exec V2 ?


Thing exec:command:Date_jour2 [command="/bin/date '+%D'", interval=15, timeout=5 ]

interval 15 means it is being executed every 15 seconds
the date command is the command to be executed in this example and needs to be replaced with your shell script


String Date_du_jour2 "Date: [%s]" { channel="exec:command:Date_jour2:output" }

all details are explained in the docs:

sorry, does not work for me… with the line in my things file, should the command be executed each 15sec. only if i view my sitemap or during all the time ? script is never called automatically…