python script not executed automatically

  • I installed libreelec using image

    Thesystem boots automatically into KODI.

    if i login over ssh with MobaXterm 20.6 i see:

    LibreELEC (official): 9.2.6 (RPi4.arm)

    LibreELEC:~ #

    So I would like to control my ambilight at the same time via hyperion.ng

    In order to shutdown the Raspi automatically when switching off power

    I use the hardware extension "StromPi3".

    Therefore a python script ("powershutdown_serialless.py)must be

    executed when starting up the Raspi.

    In the forum I found the post by "jakob" from June 13, 2020 and then made all

    the settings :

    - install "Raspberry Pi Tools" add-on

    - create the folder /storage/.kodi/userdata/scripts

    - insert lines in my powershutdown_serialless.py

    import sys

    sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')

    - put powershutdown_serialless.py into /storage/.kodi/userdata/scripts

    - create /storage/.config/autostart.sh

    both files attached in the datei.zip.

    When i start the powershutdown_serialless.py from an ssh terminal see hier :

    LibreELEC (official): 9.2.6 (RPi4.arm)

    LibreELEC:~ #

    LibreELEC:~ # python /storage/.kodi/userdata/scripts/powershutdown_serialless.py &

    LibreELEC:~ # Safe Shutdown in the case of Powerfailure (CTRL-C for exit)

    it works fine. But on booting the raspi the script "powershutdown_serialless.py"

    is not executed.

    Where is the mistake ?

    many thanks for the support

  • Check your autostart.sh script if you just created it for any errors DOS format and not UNIX?

    this should start your script like on startup..

    Code
    sh /storage/.config/autostart.sh

    run this on autostart.sh

    Code
    dos2unix /storage/.config/autostart.sh
    
    chmod 777 /storage/.config/autostart.sh

    the autostart.sh in your zip file is in windows dos...needs to be unix format..but might have changed by uploading or downloading or whatever..not sure...try those 2 commands and you should be good to go..

  • the problem was definitely autostart.sh

    I logged in with a terminal program (mobaxterm) and the /storage/.config/autostart.sh file was just one line
    python /storage/.kodi/userdata/scripts/powershutdown_serialless.py &

    created and the rights set with chmod.
    the command is now executed correctly. after entering ps -ef i can also see the running process. 566 root 0:00 python /storage/.kodi/userdata/scripts/powershutdown_serialless.py

    it would be nice if a message could be sent to all logged-in terminals in the event of a power failure - is that possible?

    the print commands from the powershutdown_serialless.py script do not arrive on a logged-in terminal

    Many Thanks

    Edited once, last by aldebaranhg (February 11, 2021 at 2:59 PM).

  • try before line 50 in your script add

    Code
    os.system("echo "Raspberry Pi Shutdown!" >/dev/pts/1") 

    that is for 1 open terminal


    if you have more then

    to find all open terminals

    Code
    find /dev/pts

    then you can edit your script ex

    Code
    os.system("echo "Raspberry Pi Shutdown!" >/dev/pts/1")
    os.system("echo "Raspberry Pi Shutdown!" >/dev/pts/2")
    os.system("echo "Raspberry Pi Shutdown!" >/dev/pts/3")

    etc


    that should send a message to all terminals

    "Raspberry Pi Shutdown!"

    Edited 3 times, last by Mario77 (February 11, 2021 at 7:42 PM).

  • thank you for your prompt reply
    Unfortunately I don't get any output on my terminal (MobaXterm via ssh)
    when I insert the new line:
    if x> = ShutdownTimer:

    print ("Raspberry Pi Shutdown!")

    os.system ("echo" Raspberry Pi Shutdown! "> / dev / pts / 1")

    time.sleep (5)

    os.system ("shutdown -h now")

    the modified script is no longer executed - no display of 687 root 0:00 python /storage/.kodi/userdata/scripts/powershutdown_serialless.py
    more about the processes at ps -ef

    I also tried to add a waiting time so that the message could be read, but it didn't work either.

    Edited once, last by aldebaranhg: another test (February 11, 2021 at 8:44 PM).

  • additive
    sh /storage/.config/autostart.sh results in:
    LibreELEC: ~ # sh /storage/.config/autostart.sh
    LibreELEC: ~ # File "/storage/.kodi/userdata/scripts/powershutdown_serialless.py", line 51 os.system ("echo" Raspberry Pi Shutdown! "> / dev / pts / 1") ^
    SyntaxError: invalid syntax

  • additive
    sh /storage/.config/autostart.sh results in:
    LibreELEC: ~ # sh /storage/.config/autostart.sh
    LibreELEC: ~ # File "/storage/.kodi/userdata/scripts/powershutdown_serialless.py", line 51 os.system ("echo" Raspberry Pi Shutdown! "> / dev / pts / 1") ^
    SyntaxError: invalid syntax

    Code
    os.system("echo "Raspberry Pi Shutdown!" >/dev/pts/1")

    try copy and paste this exactly..

    below is yours...you moved few bits:

    Code
    os.system ("echo" Raspberry Pi Shutdown! "> / dev / pts / 1")

    It worked here...no reason it doesn't work for you...you can open more terminal windows to test from one to the other and you ll see the message popping up..

    I m not great with python hence i gave you the shell version of the command..you r basically sending an sh command from a py script..

    I m not sure what your script is for but if it's something important you can even send an automated email from libreelec to your email..

  • i copied the code exactly. Maybe some characters (space) got into it through later editing (google translater).
    Sorry, I still have to learn how to correctly compose my posts!
    I think the python interpreter cannot recognize the expression os.system..... The normal shellcommando

    LibreELEC: ~ # os.system ("echo" Raspberry Pi Shutdown! "> / Dev / pts / 0")
    sh: syntax error: unexpected word (expecting ")") does not work under Libreelec either.

    with LibreELEC: ~ / .config # echo "3456"> / dev / pts / 0
    3456
    can I send texts between logged-in terminals.

    to your question:
    the script powershutdown_serialless shuts down the raspi at power off. That works fine. I can also do without the additional issue of a message.

    when I start the script manually:
    LibreELEC: ~ / .kodi / userdata / scripts # python powershutdown_serialless.py &
    LibreELEC: ~ / .kodi / userdata / scripts # Safe Shutdown in the case of Powerfailure (CTRL-C for exit)
    Here you can also see that the script is working properly:
    messages are issued.
    Case 1 momentary power failure
    LibreELEC: ~ / .config #
    LibreELEC: ~ / .config # Raspberry Pi Powerfail detected
    Raspberry Pi Power Back Detected!

    Case 2 long failure power
    LibreELEC: ~ / .config #
    LibreELEC: ~ / .config # Raspberry Pi Powerfail detected
    Raspberry Pi Shutdown!

    The main thing is that the script is started automatically and works properly.
    Thanks again :)