How can I run the program in the background? And the problem with access point



  • I want my program on Python 3 to start automatically with the launch of Omega 2. I added an entry to the rc.local file: python3 /tmp/mounts/SD-P1/program.py &, but the program did not start.
    How can I run the program in the background so that it does not end with the end of the session?

    Also on my omega 2 there is a problem with the access point. When connecting to Wi-Fi Omega 2, a password is requested, which is 12345678 by default, but it was remembered before and the connection was made automatically. I did not change the connection settings. And sometimes when you try to connect, the access point disappears. I have to restart Omega for fixed it.



  • @CAP-33

    How can I run the program in the background so that it does not end with the end of the session?

    Probably the system cannot find the python application using the PATH available to it at the time of execution. I'd suggest using the full path to the binary. Something along the lines of:

    /usr/bin/python3 /tmp/mounts/SD-P1/program.py &
    


  • @cas
    Unfortunately it did not help



  • @CAP-33
    Does it run if you move your python script into /root?
    If it does, then probably the external storage hasn't mounted at the time the script is being run.
    You did put it before the exit 0, correct?

    You can try redirecting all script output to a log file:

    /usr/bin/python3 /tmp/mounts/SD-P1/program.py >> /root/program.log 2>&1 &
    

    And then review the log file for any hints as to what might be happening.



  • @cas
    Are there ways to run scripts automatically when Omega is fully loaded?



  • @CAP-33

    Are there ways to run scripts automatically when Omega is fully loaded?

    I don't think that there is. As a user, the /etc/rc.local is the usual place for you to put your startup scripts, with the expectation that it is among the last of the system startup scripts to be executed, but reality will teach you that it's not possible to guarantee this to be true.

    The problem is to understand at what point 'fully loaded' occurs. You could spend effort to time everything to the point where everything is finished loading, but then the next system update could introduce something new that extends that point in time. It's a moving goalpost.

    I would suggest that you understand the dependencies that need to be in place for your script to execute, then check that those are in place as part of your script initialisation process.

    Some people will suggest that as an easy option, just insert timed delays such as sleep 60 to wait 1 minute before executing your script and this may work for you, but it's still a bit of a gamble.

    If the only prerequisite is that the script is available, you could just delay executing until the script is available. Something like:

    # while the script file is not found
    while [ ! -f /tmp/mounts/SD-P1/program.py ]
    do
     # wait 10 seconds
     sleep 10
    done
    /usr/bin/python3 /tmp/mounts/SD-P1/program.py &
    # Do the next thing
    

    Unfortunately, if some external event prevents the external storage from ever mounting, you will never get to # Do the next thing.

    To avoid that, you could implement an escape condition such as:

    TRY=10
    # while the script file is not found and we haven't tried this 10 times
    while [ ! -f /tmp/mounts/SD-P1/program.py ] && [ ${TRY} -gt 0 ]
    do
     # wait 10 seconds
     sleep 10
     TRY=`expr ${TRY} - 1`
    done
    if [ -f /tmp/mounts/SD-P1/program.py ]; then
     /usr/bin/python3 /tmp/mounts/SD-P1/program.py &
    fi
    # Do the next thing
    

    So in this scenario, you'll introduce a maximum 5 minute (10x30s=300s) delay and only execute the python script if it exists after exiting the delay loop. But if the file never becomes available, you can still get to # Do the next thing.

    Note this is untested shellcode, so there may be bugs in it ;-)



  • @cas
    Thank. I realized that the my program on Python is working. I have another problem:
    I want that when you start Omega, the file is sent to another computer via psync. I entred the command rsync -e "ssh -i /root/.ssh/id_rsa" /tmp/mounts/SD-P1/data.dat user@192.168.0.19:/home/user/Desktop to the file rc.local. It would seem that everything should be in order, but the log shows it: Host '192.168.0.19' is not in the trusted hosts file.
    Do you want to continue connecting? (y/n).
    At the same time, if i enter this command manually, then everything works. I think that by the time the command start, the file with the saved networks is not loaded yet and for this Omega asks for confirmation. How to fix this?



  • @CAP-33
    The known_hosts file doesn't seem to be something you can pass to ssh command at runtime, so if it can't find it in the user's home directory, try adding the relevant host key to the system wide known_hosts file: /etc/ssh/ssh_known_hosts

    /etc/ssh/ssh_known_hosts
    Systemwide list of known host keys. This file should be prepared by the system administrator to contain the public host keys of all machines in the organization. It should be world-readable.

    Assuming OpenWRT/LEDE implementation of ssh implements this...

    It could also be that you only see the connection confirmation request on your first (non-interactive because you are running it in the startup script) attempt. The user's known hosts file (~/.ssh/known_hosts) would be created on your second attempt (interactive because you run it from the shell prompt) and should be there for each subsequent connection attempt (interactive and non-interactive) until such time as it is removed.



  • @cas
    Thank you. I added the line with deviсe key to the file /.ssh/_known_hosts and it all worked.



  • @CAP-33
    Glad to hear it, happy hacking!!


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.