Search code examples
pythonbashnetwork-programmingnvidia-jetson-nano

Run python script when internet connection becomes available on Jetson Nano (Ubuntu 18.04)


I need to setup a Jetson Nano device so that a Python script is launched everytime an Internet connection is available.

So, referring to this question, I did the following:

  • I created the 'run_when_connection_available' script:
#!/bin/sh

# create a dummy folder to check script execution
mkdir /home /user_name/dummy_folder_00

# kill previous instances of the system
pkill python3

# move to folder with python script and launch it
cd /home/user_name/projects/folder
/usr/bin/python3 launcher.py --arg01 --arg02 ...

# create another dummy folder to check script execution
mkdir /home /user_name/dummy_folder_01

  • I made this script executable and I copied it to /etc/network/if-up.d

Now, everytime I plug the ethernet cable out and in again, I can see the dummy folders are created in /home/user_name, but the python script isn't launched (at least, it doesn't appear in the system monitor). I tried running the command in the script from the terminal, and everything works fine, the python program starts as expected. Am I doing something wrong?


Solution

  • Ok, I guess it was a matter of permissions, I solved it by running everything as user_name, so I modified the script as

    sudo -user user_name /usr/bin/python3 launcher.py --arg01 --arg02 ...