I try to download a file with curl directly after logging into Gnome. This usually fails because mostly the WiFi connection is only established after login. If I wait long enough in the login screen before logging in, the connection is already established and the download works.
So far I have used Manjaro. WiFi was already active long before the login screen of GDM was even displayed. The download therefore always worked.
The download is initiated with a *.desktop file in ~/.config/autostart.
Is there another way to start the download after the user is logged in and the WiFi connection is really ready?
Nice. I will try the systemd unit. Meanwhile, i have added a loop in the script, which helps a little bit:
maxwait=15 if [[ $(nm-online -x) != *"online"* ]]; then echo "missing internet connection, waiting..." for (( i = 1; i <= maxwait; ++i )); do sleep 1 & echo $i if [[ $(nm-online -x) == *"online"* ]]; then break fi if [[ $i -eq $maxwait ]]; then echo "No internet connection" exit 1 fi wait done fi
In my test, this exits the script after 15 seconds without connection, but continues, when the connection is available or is established within this time.
But i think, its a nice idea, to add this to the script AND use the systemd unit together.
With these kinds of things, where you need to manage state (waiting, executing, failed, etc), it is very easy to miss a case or transition and generally better to rely on proven tech.
Let the waiting for network connection and retrying be done by systemd, half the internet runs on it. You can trust that it won’t mess that part up. Write only what is specific to you in your script.