Best way to autostart a script with network delay after login?

Hi Mabox community,

I’m trying to set up a custom script that runs on login, but only after the network is fully up (I’m syncing a few dotfiles from a private Git repo).

I added the script to my Openbox autostart, but it sometimes runs before Wi-Fi connects, which causes it to fail.

Any suggestions for a lightweight way to delay execution until the system confirms an active network connection? Maybe using nmcli or something in the Mabox toolkit?

Appreciate any tips or examples!

— Jhonn Mick

Hello @jhonnmick and welcome to the forum :slight_smile:

I would try something like:

(sleep 10s && myscript) &

at the very end of the ~/.config/openbox/autostart file.

Thanks @napcok

I ended up using a simple loop with nmcli to check for an active connection before running the script. Added this to my autostart instead of calling the sync script directly:

while ! nmcli -t -f STATE g | grep -q "connected"; do
  sleep 2
done
~/.config/scripts/sync-dotfiles.sh

It’s lightweight, reliable, and does exactly what I needed. Appreciate your support!

— Jhonn Mick

1 Like