R
R
Riateche2011-09-11 14:14:55
linux
Riateche, 2011-09-11 14:14:55

Programmatically detect when Network Manager connects to network

I would like to add a browser to startup, but so that it does not open if I'm not at home (no wi-fi connection). As far as I know, nm provides similar functionality. For example, pidgin does not try to connect when there is no connection in nm, but simply waits for a connection. I would like to write a script that waits a minute for a connection and launches a browser if a connection is made. Where to dig?

OS - Ubuntu 11.04.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eol, 2011-09-11
@Eol

Dig in the direction of DBus and, accordingly, the NetworkManager'a interface for it.

M
m08pvv, 2011-09-11
@m08pvv

As an option, add a script to /etc/NetworkManager/dispatcher.d/
For example, But I didn’t fully understand the bugs with environment variables ...
#!/bin/bash
# первый параметр скрипта - интерфейс
IF=$1
# второй параметр скрипта - состояние (up/down/pre-up/post-down)
STATUS=$2
# Если интерфейс тот, который мне нужен и он поднялся, то проверяем дальше
if [ "$IF" = "wlan0" ] && [ "$STATUS" = "up" ];
then
# Если мы подключились к своей точке (00:1E:58:FF:AF:FA)
iwconfig "wlan0" | grep "00:1E:58:FF:AF:FA" > /dev/null
if [ $? == "0" ];
then
# То выполняем запуск гуглохрома от имени юзера user
env DISPLAY=:0.0 su user -l -c google-chrome &
exit $?
fi
fi

I
Ilya Kovalevsky, 2011-09-11
@namespace

My advice to you: dig towards Qt. And everything will be clear there.)

C
ComodoHacker, 2011-09-11
@ComodoHacker

Or maybe just

iwconfig wlan0 |grep --quiet <SID> && firefox

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question