We have moved to a new Sailfish OS Forum. Please start new discussions there.
3

Run script after connected to wifi

asked 2014-06-27 00:03:05 +0300

htmm gravatar image

Hi,

is there a way to run a script after I connected or disconnected to/from a (wifi) network? I want to automate the VPN connection after I connected to certain networks.

Thanks!

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
3

answered 2014-06-27 02:34:51 +0300

Schturman gravatar image

Yep.. You can run script like this:

#!/bin/bash

connection=$(/usr/lib/qt5/bin/qdbus --system net.connman /net/connman/technology/wifi net.connman.Technology.GetProperties|grep Conn|awk '{print $2}')

if [[  "$connection" == "true" ]]; then
echo "Connected to WIFI" #Do what your need.
else
echo "NOT connected !" #Do what your need.
fi
edit flag offensive delete publish link more

Comments

Hi, Thanks for the answer, but what will trigger this script?

htmm ( 2014-07-02 01:03:46 +0300 )edit

The above script only queries the current state. You could use it to poll the connection state, but that would not be ideal. Instead I suggest you listen for changes to the Connected property of the /net/connman/technology/wifi DBus path.

Aaron McCarthy ( 2014-07-03 06:53:30 +0300 )edit
Login/Signup to Answer

Question tools

Follow
6 followers

Stats

Asked: 2014-06-27 00:03:05 +0300

Seen: 1,742 times

Last updated: Jun 27 '14