Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There is a specific wireless network I connect to that requires me to use vpnc to access the internet. If I make a script to do this, is there a way to set it up so every time I connect to this network, the script is run? To be clear, I don't want this script run with most wireless connections, just one specific one.

share|improve this question
up vote 6 down vote accepted

You can use upstart for this. Upstart is able to catch the event of connecting to a wireless network (or a network in general) and use that as the prerequisite for running your script.

Upstart is already used by lots of scripts in Ubuntu and will eventually replace all the System V init scripts at bootup time.

share|improve this answer

Network Manager runs ALL of the scripts in the /etc/NetworkManager/dispatcher.d/ directory (those owned by root, that are executable, that are not readable by other users, and not setuid).

Environment variables are set and passed to this script by Network manager. You'll be interested in the CONNECTION_UUID environment variable (contains a unique string).

So, to solve your problem (execute a script when a particular wireless network is connected to):

1) find out the uuid of the wireless connection you're interested in (by looking inside the appropriate connection file in the /etc/NetworkManager/system-connections/ directory).

2) write a bash (or perl, or python, or whatever) script that does what you want if the environment variable CONNECTION_UUID is a match to the uuid of the wireless network in (1) above.

3) put this script into /etc/NetworkManager/dispatcher.d/ and set the owner and permissions appropriately.

further reading: man networkmanager ( and a litte poking around the scripts in the directories mentioned above).

share|improve this answer
On a Natty machine which is on wi-fi, that directory is empty. Does this depend on system version? – nealmcb May 18 '11 at 20:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.