Rule cant find Script directory

  • Platform information:
    Running openhab 2 on a synology NAS.

Im trying to run a script from the script folder in my openhab installation.

The script looks like this:
!/bin/bash
tac /volume1/homes/openhab/userdata/logs/mirhome.log | head -n 10 > /volume1/web/mirhome.log
tac /volume1/homes/openhab/userdata/logs/openhab.log | head -n 50 > /volume1/web/openhab.log
date +"%d.%m.%Y %T"

The Rule looks like this:
rule “Script”
when
Time cron “0 34 16 * * ?”
then
executeCommandLine("/volume1/homes/openhab/conf/scripts/openhablogs.sh")
end

When the rule fires, done with a cron job, i get the following log error:
couldn’t execute commandLine ‘/volume1/homes//openhab/conf/scripts/openhablogs.sh’

If i run this from the CLI: tac /volume1/homes/openhab/userdata/logs/mirhome.log | head -n 10 > /volume1/web/mirhome.log
the command is done.

I tried a lot of possible paths
/homes/openhab/conf/scripts/openhablogs.sh etc.
none is working.
How can i find the right path to fill into the rule?
Any ideas are appreciated
Thnx

The path if given absolute should be fine.
Eventually permissions are not ? The user openhab runs as must be able to execute that.

Hi, thnx for the quick answer. I just tried the standard Synology admin and it works, with the Openhab user it gives me a no permission error. “-sh: /volume1/web/mirhome.log: Permission denied”
I changed all the permissions on the NAS to the same as the admin user has. I still get the error.
Is there a way to start the script with the admin NAS user ?

What about full path to the tac command?

No. Just give it proper “any” permissions.
And running OH on Synology is not really recommended, expect all sorts of issues there.

That should be the full path… at least for the synology

No. You are not sure where the script is run from and what path environment is set. Usually you can type which tac or whereis tac to conf the complete path.
Even if it was in the current working directory then it should be specified as ./tac. Many times the current directory is not in the execution path.

Hi, not sure what you mean. How can i find the full path?
Please excuse my little knowing of all this stuff.
From the cli its working now with the openhab user rights.
From the rule i still get: “couldn’t execute commandLine ‘/volume1/homes//openhab/conf/scripts/openhablogs.sh’”

It is good it runs as the openhab user but when you login as that user a path environment is set up that is likely different than when the script is run. That is why it is safest to put the full path for all commands in a script. Tou need the path for the tac command.

How do i get the full path ?

One of these commands can tell you the full path.

Here is the answer.

Thnx a lot.
I get /bin/tac in the console. So how do i use that in my rule now?
or do i need to put that in the script before the tac command ?

In your script, replace tac with /bin/tac. You are then telling the system where that command is located. Hopefully that will resolve the issue. If not, it is good standard practice anyway.

Hi, still not working.
I think the problem i have is that the path to the Script is not right, cause it cant find the script itself.
But i cant see an error in the path…
Funny that it works in cli…but not in a rule…

I have not executed commands with OpenHAB.
There is a hint here.


In your rule you could try executeCommandLine("/volume1/homes/openhab/conf/scripts/openhablogs.sh", 10000)
Apparently you need to specify how long the script may run.

EDIT: More troubleshooting hints. How to solve Exec binding problems

Tried a little more and now i get this message:
“Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “/volume1/homes/openhab/conf/scripts/openhablogs.sh” (in directory “.”): error=2, No such file or directory)”

?! Does this mean it finds the script?

It means it doesn’t find the script or the openhab user doesn’t have permission to read/execute it.

same as above…I think you have permission issue.
Try giving your openhab user permission on the script with:

chown openhab:openhab /volume1/homes/openhab/conf/scripts/openhablogs.sh

Of course if “openhab” is the user your sinology created.

And be sure your script is executable (you said you issued the command inside the script from CLI not the script itself) with:

chmod u+x /volume1/homes/openhab/conf/scripts/openhablogs.sh

If none of that it’s working you can try to “open” permission to “everyone” giving this command

chmod 777 /volume1/homes/openhab/conf/scripts/openhablogs.sh

But I would first go trying to give specific permission to openhab…I don’t personally like giving the 777 permission.

Just a silly question: you don’t happen to run OH in a Docker conatiner by any change? :wink:
Some Synology models do support that (the ones with an Intel CPU), so just checking…