1

I want to run an app on startup called Software Updater, Generally what I'd do is add it to the Startup apps list and It'd start up every time I boot. What I want to do instead is I want to run it only when WiFi is connected.

So basically

  • Check for connected WiFi, if it's connected then Run Software Updater
  • If it's not then don't do anything.

Saved WiFi's that are in range are automatically connected on boot.

2
  • 1
    How do you run this software updater? and how do you connect to your Wi-Fi (using Network Manager or ...)?
    – Ravexina
    Jul 5, 2017 at 7:15
  • @Ravexina Software updater is an app bundled with Ubuntu Gnome. and I'm looking for automatically connected WiFi here, saved WiFi that are in range. and I generally use Gnome's top right menu to connect it otherwise. Jul 5, 2017 at 7:28

1 Answer 1

2
+50

If using NetworkManager, you can put a script in /etc/NetworkManager/dispatcher.d and have it "listen" for a wifi UP event. Note you may have to change the WLAN interface name

Here is an example:

#!/usr/bin/env sh

IFACE=$1 STATUS=$2
IW=/usr/bin/iw
WLAN_IFACE=wlp1s0

if [ ! -x $IW ]; then
    exit 1
fi

if [ "$IFACE" = $WLAN_IFACE ] && [ "$STATUS" = "up" ]; then
    echo "[SCRIPT] -- PUT SOMETHING HERE YOU WANT TO HIT LOGS --"
    echo "Replace this echo with a command line instruction"
fi

You could extend the above logic to only fire on a given Network, etc.

Here is a reference to NetworkManager events ($2) that may be helpful: https://developer.gnome.org/NetworkManager/stable/NetworkManager.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .