Bash script not working as I would expect

My Living Room TV is running Android TV and therefore able to receive notifications, which is very handy. So after a few searches with our friend google, I found a way to send notifications.

To make sure that I can get things working as they should I have rule created a simple rule that when runs has the following line.

executeCommandLine("/opt/openhab/conf/scripts/" + "@@" + vNotification + "@@" + ">/dev/null")

The variable vNotification contains “The Grand Tour”

This is the output from the openhab.log

2020-01-17 20:53:30.403 [INFO ] [] - executed commandLine '[/opt/openhab/conf/scripts/, The Grand Tour, >/dev/null]'

For completeness here is the bash script

nfa notify -a -t "Plex" -m "$1" -d 10s -o top-right

The result from this doesn’t display anything on the TV screen as there are two commas that shouldn’t be there for some reason. Here’s what the command should be.

/opt/openhab/conf/scripts/ 'The Grand Tour'

What do I need to change to make this work?

Try this…

executeCommandLine("/opt/openhab/conf/scripts/ \"" + vNotification + "\"")

You may need the full path to nfa. You can use which nfa or whereis nfa to determine where it is in your path,.

Try this :slight_smile:

executeCommandLine("/opt/openhab/conf/scripts/ \'" + vNotification + "\'")

Nope … the Problem is the wrong Notation in the execueCommandLine

2020-01-17 20:53:30.403 [INFO ] [] - executed commandLine '[/opt/openhab/conf/scripts/, The Grand Tour, >/dev/null]'

i usually build the whole command I want to execute in a separate string variable and put this string variable in the executecommandline. You can print it in the log before to see what it is doing.

Thanks for the suggestions, sadly none of them seem to have helped. So I’m still a little stuck as to which way I should go now.

What shows your Log, when you use my Code?

executeCommandLine("/opt/openhab/conf/scripts/ \'" + vNotification + "\'")

Without Logs we can’t find out where the Problem is :wink:

The Problem could be the Shell Script, the executeCommandLine Notation or any Problems with the right (e.g. sudo)

Silly question, I know, but just to be sure… if you use…

/opt/openhab/conf/scripts/ 'The Grand Tour'

… in a shell, does it work properly? Does the openhab account have permissions to execute the script? Try using a timeout and logging the output…

val plex_result = executeCommandLine("/opt/openhab/conf/scripts/ \"" + vNotification + "\"", 5000)
logInfo("Rules", "plex_result = [{}]", plex_result)

Also, turn on DEBUG logging for executeCommandLine by executing this in the console…

log:set DEBUG

When i running this directly at the command line it work perfectly. Which is why this is so confusing. I’m also running the command as root, so permissions shouldn’t be an issue.

I’ll change my logging to DEBUG and see what that outputs.

Again, thanks everyone for helping.

executeCommandLine is execute as User openhab

Please try this Command on Shell to check permission Problems

sudo -u openhab /opt/openhab/conf/scripts/ 'The Grand Tour'
1 Like

The openhab account shouldn’t be in sudoers, so I don’t think that will work. But @Maximo could make sure that the openhab account has permissions to the script file by executing…

chown openhab:openhab /opt/openhab/conf/scripts/
chmod u+rx /opt/openhab/conf/scripts/
1 Like

The sudo is required for the user who executes the command as user openhab. It is not the same as sudo /opt/openhab/conf/scripts/

With my line you only check this command execute as User Openhab in the shell!

 sudo -u openhab /opt/openhab/conf/scripts/ 'The Grand Tour'

you also can use this command if your User has no sudo (not openhab… your Local User)

su openhab -c /opt/openhab/conf/scripts/ 'The Grand Tour'

I don’t have an openhab user, my installation is running as root.

What installation type did you use? Package installation makes an openhab user.

I just download the zipfile and created the service definition. Using CentOS 7.

Changing to DEBUG logging hasn’t helped either, this is the output

2020-01-20 19:23:18.218 [INFO ] [] - executed commandLine '[/opt/openhab/conf/scripts/, The Grand Tour]'

And, the advice in post #9 to get a result ?

Now this is interesting. Here’s the output, which I’m totally confused by.

2020-01-20 19:40:32.216 [INFO ] [eclipse.smarthome.model.script.Rules] - plex_result = [open /root/go/src/ no such file or directory
open /root/go/src/ no such file or directory
open /root/go/src/ no such file or directory]

I certainly don’t get any errors like this when running directly from the command line.

The location of the file gopher.png is here on my server.