ExecuteCommandLine Runnng scripts within scripts

I have 3 shell scripts
Script 1 calls scripts 2 and 3
I can successfully execute this from the command line

If i execute it in a rule, it runs script 1, but doesn’t execute scripts 2 and 3(when run from openhab in a rule)

Here is script 1:

rm /etc/openhab2/html/MBGar1-01.jpg

sh ./MailBoxGarage1.sh
sh ./MailBoxGarage2.sh

Here is the rule:
executeCommandLine(“bash /etc/openhab2/MailBoxSnaps.sh”)

I know it runs because it removes the jpg; it just doesn’t run those 2 other shell scripts when run from an openhab rule.

All 3 scripts have openhab as the owner and group owner and have rwx on owner, rx on group and rx on all others

Any idea why script 1 can call scripts 2 and 3 from a command line but now when run from a rule in openhab?

  • Try using the full path to sh (i.e. /bin/sh)
  • Try using the full path to the two scripts

When openHAB executes scripts it not only isn’t running as a normal user but it isn’t running with a full shell environment. Therefore you can’t always trust it will have things like a PATH environment properly configured.

Also from the openHAB context ./ is probably not in the same folder where the three shell scripts are located. If executeCommandLine(./MailBoxSnaps.sh) does not work that would explain that.

Finally, it is redundant to call bash MainBoxSnaps.sh if you have #!/bin/bash as the first line of your script. That is the whole point of that line, to tell the interpreter to execute the following script using that command. I suspect the sh es are redundant as well.

Is there a reason you have this all separated into three separate scripts?

Will try that and see what happens

Did not know about the redundancy…i saw an example like that and have used it ever since in other scripts.

Why 3 separate scripts…when i called the last two from the first, i coudln’t get it to work; so i call all 3 from 3 execute commands in a rule. Might be a race condition, wasn’t sure and not really a Linux expect so i found a way to “make it work” :slight_smile:

Full path worked :slight_smile:
Removed the sh as well.


Most likely was. When you call executeCommandLine without a timeout argument it doesn’t wait for the command to complete until it returns and instead returns immediately. It would have worked if you added a number (timeout in milliseconds) as the second argument to executeCommandLine.