[SOLVED] executeCommandLine: command "echo" is not going to be executed


I"d like to write “ON” and “OFF” to a simple text-file whenever a switch is changing.
The switch is changing perfectly each 30 seconds, but the “ON” and “OFF” is not going to be written to the text-file, althoug I have given the necessary privileges (chmod 777 for test.txt) and put openhab into the openhabian-group to be able to write there.

This is the code I use in default.rules:

rule "timeclock test ON"

  Time cron "30 * * ? * MON-SUN *"
  sendCommand(PifaceSwitch1, ON)
  executeCommandLine("echo \"ON\" > /home/openhabian/status/test.txt")

rule "timeclock test OFF"

  Time cron "0 * * ? * MON-SUN *"
  sendCommand(PifaceSwitch1, OFF)
  executeCommandLine("echo \"OFF\" > /home/openhabian/status/test.txt")

In the log-file, I get the message that the command has been executed successfully:

19-01-26 16:55:30.033 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'echo "ON" > /home/openhabian/status/test.txt' 
2019-01-26 16:56:00.033 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'echo "OFF" > /home/openhabian/status/test.txt'

But when looking into test.txt, the file is still empty. But I can write into it (even as user openhab, I controlled this).

What is my mistake?
Can anybody give me some hints?

Thank you!
Cu Markus

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Raspbian GNU/Linux 9 (stretch)
    • Java Runtime Environment: OpenJDK (Zulu Embedded
    • openHAB version: OpenHAB 2.4.0-1

I may be wrong, wouldn’t be the first time, but I think you need something like a python script that will execute and write the text your wanting. I’ve never seen a post on the forum where OH will simply write into a .txt file like your describing but I’m sure it can be done with a script.

From the actions docs:

Note: The commandLine variable often has to use a special format where @@ needs to be used in place of spaces. For example the bash command touch somefile will have to be written as touch@@somefile



Hi H102:
I tried to do it the way you recommended: Created two python-files, one for writing “ON” and another for “OFF”. I made them executable and tried them, everything well - I got the “ons” and “offs” whenever I was running the python scripts.
Then I put the whole thing into rules - but nothing happens, although logging is telling the contrary.
May be another mistake happening, but seems not to be the solution, at least the way I did it:

This is what I put in the default.rules:


But the python script never was executed (it worked well when executed by hand).

Nevertheless thank you for suggestion!

Hi vzorglub:

I changed it with @@ instead of the blanks:


But nothing changing, although the logging tells me now:

19-01-26 18:28:30.676 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[echo, "ON", >, /home/openhabian/status/socket_01.txt]'
2019-01-26 18:29:00.034 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '[echo, "OFF", >, /home/openhabian/status/socket_01.txt]'

That simple things can be made so dificult :-/

Thank you nevertheless!

Hello H102:

When reading again the observations about the common errors of the executeCommandLine, I found out, that I had forgotten to put the “python” command in my CommandLine:

executeCommandLine("python /etc/openhab2/filename-etc.etc")

This worked ‘out of the box’ (even with blanks) - so thank you very much for your suggestion to try it with python scripts!