Question about autostart.sh

  • Hi,

    I am having a hard time solving this issue, mainly 'coz I'm noob. Ahem, here it is:

    I have 2 python scripts on my Rpi3. One is for setting a GPIO pin to "high" (it is called A.py), and the other for dealing with the "pi-supply" switch thing (it is B.py).

    The "Pi-Supply" code is basically a loop that waits for the user to press a button linked to the correct GPIO pin, and then halt the Raspberry.

    I did add the two scripts in autostart.sh. Both scripts work fine when I call them from Putty remotely. But when listed in autostart.sh, one does not actually start (B.py). Mainly, I suppose, 'coz it is a loop.

    I have tried different syntaxes, such as:

    (
    python A.py;
    python B.py
    )&

    And various others. Without success.

    So my questions are:

    1) How would you key in the call to these 2 scripts inside autostart.sh ?
    2) Is there a log of autostart.sh or how can I setup one?

    Thanks a lot for your support, and thx to Libreelec team for the great evenings spent with my wife watching movies :)

  • Bash
    #!/bin/bash
    (python /path/to/A.py)&
    (python /path/to/B.py)&
    exit

    ^^ this executes each python script independently so they run in the background, allowing autostart.sh to complete. The bash shebang and exit aren't strictly necessary; I included them so you understand start/finish of the script.

    Edited once, last by chewitt (August 15, 2016 at 7:56 AM).

  • Hi, and thanks to both of U for your support.

    I tried the syntax proposed, no luck. So I think one script is actually hanging, but I do not know why. My script "A.py" does not seem to hang, it works fine and returns to command prompt as soon as I called it. Script "B.py" is hanging, due to the loop I believe (CTRL+C is the only way to get back to command prompt when I'm in Putty).

    Here is code of A.py:

    Python
    # Import the modules to send commands to the system and access GPIO pins
    from subprocess import call
    import sys
    sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
    import RPi.GPIO as gpio
    
    
    gpio.setmode(gpio.BOARD) # Set pin numbering to board numbering
    gpio.setup(8,gpio.OUT)
    gpio.output(8,1)

    And for B.py, it is the code shown in the first block of the Pi-Supply code examples page:

    Pi Supply Switch v1.1 Code Examples • Pi Supply

    Thanks a lot for your help!

  • If both script works from console then maybe your file autostart.sh is in DOS format and not UNIX? Use text editor like Metapad for editing.

    And to test the autostart just type

    Code
    sh /storage/.config/autostart.sh


    It should work just as when you type both commands separetely.


  • If both script works from console then maybe your file autostart.sh is in DOS format and not UNIX? Use text editor like Metapad for editing.

    And to test the autostart just type

    Code
    sh /storage/.config/autostart.sh


    It should work just as when you type both commands separetely.


    sh... that's what I was looking for.

    Here is the output when trying to launch the script from console:

    Code
    Traceback (most recent call last):
      File "/storage/PiSupply/softshut.py", line 21, in <module>
        loop() # Run the loop function to keep script running
      File "/storage/PiSupply/softshut.py", line 9, in loop
        raw_input()
    EOFError: EOF when reading a line

    So it seems the Pi-Supply code is causing me trouble... Maybe the solution is straightforward?

    Again, thanks for the support.
    [hr]
    Don't bother, the code was not the best one. I looked at the comments on the Pi-Supply website and found a code that works.

    Again, thanks for your help, and sorry for the very basic questions. Have a good day!

    Edited once, last by meatpuppet (August 15, 2016 at 1:19 PM).