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.
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
ip link show $interfaceprints a line with the status of the interface (in this case
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; doneexecutes
sleep 10until the command was successful, i.e. until
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.