Command working from shell but not from autostart.sh script and keymap.xml's System.Exec(exec)

Fringe use case for sure but still…

In autostart.sh I call a Day-Night.sh script that checks the time and invokes three different scripts for Day/Evening/Night use. The three scripts use wget to send commands to my Denon AVR and bscpylgtvcommand (GitHub - chros73/bscpylgtv: Library to control webOS based LG TV devices) to send commands to my LG TV.
I would also like to have the same functionality mapped to my remote as I used to do on my HTPC.

Now… if I SSH into CoreELEC, I can use bscpylgtvcommand just fine from command line. I installed the required python components from Entware and it works perfectly.

But when I try to call it from autostart.sh or using System.Exec(exec) in my keymap, it’s as if the command is not executed at all.

The command is installed in /opt/bin, it has execute permissions for all users (755) and contains the following:

#!/opt/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from bscpylgtv.utils import bscpylgtvcommand
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(bscpylgtvcommand())

As an example, the day script contains:

#!/bin/bash

wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?PSDEH%20OFF
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?PSDYNVOL%20OFF
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?PSLFC%20OFF
sleep 0.3
wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?PSCNTAMT%2005
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?SPPR%202
sleep 1.0
wget -O - > /dev/null 2>&1 192.168.0.21:8080/goform/formiPhoneAppDirect.xml?MV54
bscpylgtvcommand 192.168.0.36 set_current_picture_mode filmMaker

All the wget commands are executed with no problem. The bscpylgtvcommand is not, even though it works perfectly from ssh comand line.

EDIT: to clarify, the above bash script works perfectly, including the command sent to the TV through bscpylgtvcommand, when invoked from the ssh command line. But the same script does not see bscpylgtvcommand working from autostart.sh or keymap.xml when using System.Exec functionality. All the wget instructions do, but bscpylgtvcommand doesn’t.

Any ideas?

You need to have full path in autostart for bscpylgtvcommand if installed from entware… :wink:

Did that, now autostart.sh is like this:

echo Y > /sys/module/hdmitx20/parameters/dovi_tv_led_no_colorimetry
remotecfg /storage/.config/remote2.conf
/storage/.config/scripts/Day-Night.sh

The Day-Night.sh script works just fine, calling the relevant script (Night, Evening or Day) correctly.

As an example, the modified Day script is now like this:

#!/bin/bash

wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?PSDEH%20OFF
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?PSDYNVOL%20OFF
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?PSLFC%20OFF
sleep 0.3
wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?PSCNTAMT%2005
sleep 0.2
wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?SPPR%202
sleep 1.0
wget -O - > /dev/null 2>&1 192.168.178.21:8080/goform/formiPhoneAppDirect.xml?MV54
/storage/.opt/bin/bscpylgtvcommand 192.168.178.36 set_current_picture_mode filmMaker

See last line where I use full path to the command.

I have tried using systemctl status kodi-autostart.service -l --no-pager and the output provides some info, I suppose.

● kodi-autostart.service - Kodi user autostart script
     Loaded: loaded (/usr/lib/systemd/system/kodi-autostart.service; disabled; preset: disabled)
     Active: active (exited) since Thu 2024-05-30 14:10:02 CEST; 19s ago
    Process: 3931 ExecStart=/bin/sh -c . /etc/profile; test -f /storage/.config/autostart.sh && exec /bin/sh /storage/.config/autostart.sh (code=exited, status=1/FAILURE)
   Main PID: 3931 (code=exited, status=1/FAILURE)

May 30 14:10:02 CoreELEC sh[4009]:     self.check_raise_error()
May 30 14:10:02 CoreELEC sh[4009]:   File "/opt/lib/python3.11/site-packages/sqlitedict.py", line 606, in check_raise_error
May 30 14:10:02 CoreELEC sh[4009]:     reraise(e_type, e_value, e_tb)
May 30 14:10:02 CoreELEC sh[4009]:   File "/opt/lib/python3.11/site-packages/sqlitedict.py", line 46, in reraise
May 30 14:10:02 CoreELEC sh[4009]:     raise value.with_traceback(tb)
May 30 14:10:02 CoreELEC sh[4009]:   File "/opt/lib/python3.11/site-packages/sqlitedict.py", line 474, in _connect
May 30 14:10:02 CoreELEC sh[4009]:     conn = sqlite3.connect(self.filename, check_same_thread=False)
May 30 14:10:02 CoreELEC sh[4009]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 30 14:10:02 CoreELEC sh[4009]: sqlite3.OperationalError: unable to open database file
May 30 14:10:02 CoreELEC systemd[1]: Finished kodi-autostart.service.

While this could explain why that portion of the script fails in autostart, I still don’t understand why it should fail when CoreELEC is fully started and the same exact script works just fine from SSH command line.

(To note: without the full path, you were absolutely right, the output becomes “command not found”, so it was most definitely a step in the right direction)

EDIT: the above probably could help in debugging the autostart thing, but the problem with the script not working from within Kodi, when mapped to a remote key is even more mysterious (autostart might have a problem with python not being fully started or something similar).
Activating debug log, when pressing the button I only get

2024-05-30 14:30:42.047 T:4033 debug <general>: HandleKey: l (0xf04c) pressed, window 10016, action is System.Exec(/storage/.config/scripts/day_mode_script.sh)

But no information whatsoever on the script’s output (result is all the wget commands are executed but the bscpylgtvcommand is not).

In file lg_constants.py did you set
DB_PATH=""
or
DB_PATH="/storage/.config/.aiopylgtv.sqlite"

I see .aiopylgtv.sqlite file under /storage/.config/scripts/ which is where the scripts I invoke are located. It’s not under /storage/.config

Also, I searched for the file lg_constants.py using find -name lg_constants.py but it couldn’t find it anywhere? Where did you get that filename from?

Then I assume DB_PATH is set in some other file. Use grep to find it.
Because I think the script just doesn’t find it and that’s why you see the error.

I assume it should be then
DB_PATH="/storage/.config/scripts/.aiopylgtv.sqlite"

I think I got it. There’s a switch I can use to point it to where the database file is.

From inside Kodi it appears to work, now I’ll check autostart and report back with complete solution (hopefully, crossing fingers, etc.).

1 Like

Ok, yes, it was like that.

Basically I needed to use in my scripts:

/storage/.opt/bin/bscpylgtvcommand 192.168.178.36 set_current_picture_mode filmMaker -p /storage/.config/scripts/.aiopylgtv.sqlite

And it works from autostart.sh too.

BUT… while this is offtopic I wonder if anybody can tell me why, with the following in my keyboard.xml file, placed under /storage/.kodi/userdata/keymaps

<m>System.Exec(/storage/.config/scripts/night_mode_script.sh)</m>
<l>System.Exec(/storage/.config/scripts/day_mode_script.sh</l>

I get this in logs:

2024-05-30 15:22:38.869 T:4038     info <general>: Loading special://masterprofile/keymaps/keyboard.xml
2024-05-30 15:22:38.870 T:4038    error <general>: Keymapping error: no such action 'system.exec(/storage/.config/scripts/day_mode_script.sh' defined
2024-05-30 15:22:38.871 T:4038     info <general>: Loading special://profile/keymaps/keyboard.xml
2024-05-30 15:22:38.872 T:4038    error <general>: Keymapping error: no such action 'system.exec(/storage/.config/scripts/day_mode_script.sh' defined

the syntax for both night and day scripts is identical in keyboard.xml. Both used to work before (apart from the TV command for which we found the solution). Now this. What the hell is happening?!?

EDIT
Missing a parenthesis… :sweat_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.