0

I need to automatically start a GUI application at startup, but after network is up, what is the right way to do it? My OS is Lubuntu with LXDE. I tried different ways, such as crontab, rc.local and autostart with no luck.

1

If you know how you can place a startup script for LXDE (see the documentation), you can always build a custom script:

until ip link show $interface | grep -F -q "state UP"; do
    sleep 10 # wait every ten second
done
# interface is up, now start program
exec bla

Explanation:

  • ip link show $interface prints a line with the status of the interface (in this case enp0s25):

    3: enp0s25: mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000

  • grep -F -q "state UP" checks if the output contains the line state UP. If yes, it returns success (exit code 0), otherwise failure (exit code 1).

  • until … do; sleep 10; done executes sleep 10 until the command was successful, i.e. until ip shows state UP. As long as the interface is not up, wait 10 second and check again.

  • when the interface is up, the loop finishes and the following script is executed.

This is of course "busy waiting" and not an ideal solution, but will always work. (Or, use ping -W 2 -c 1 google.com >& /dev/null instead of ip … | grep if you want to ensure real internet connectivity.)

If you use some network manager, check its documentation if you can add scripts that are executed when it established a network connection. However, this may only work with root access, which complicates starting a program within your X session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.