Super User is a question and answer site for computer enthusiasts and power users. 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

Possible Duplicate:
Run script in OS X 10.6 on network connection. (like /etc/network/if-up.d/)

I set up ssh tunnels so that I can access various computers at work through our gateway. The problem is, I don't like having to always set these up each time I turn on my computer or connect/disconnect to the internet so I'm hoping that there is a way that I can automatically run a shell script to set up the tunnels whenever I connect to the internet. I have something similar setup on my workstation in the office which is running Ubuntu and it uses the /etc/network/if-up.d and if-down.d. Is there an equivalent on the Mac?

share|improve this question

marked as duplicate by Daniel Beck, BinaryMisfit Dec 3 '10 at 6:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Possible Duplicate – Daniel Beck Dec 2 '10 at 18:54
up vote 2 down vote accepted

I guess context-aware tools such as MarcoPolo can do the trick, surely if you use some shell script to set up the tunnels:

Flexible rule-based fuzzy matching on:

  • [..]
  • Assigned IP addresses
  • Active Network Links
  • Visible WiFi networks

Actions triggered by changing context (either entering or leaving), with an optional delay:

  • [..]
  • Mounting network shares (smb://, afp://, etc.)
  • Changing OS X network location
  • Quit an application
  • Running a shell script (or any other kind of script, via Platypus)
  • Establish or disconnect VPN
share|improve this answer
This is exactly the kind of thing MarcoPolo can handle and I've used it in the past to establish a VPN tunnel when ever I connect to a specific network (when moving a computer from work to home and back again). Very handy tool. – Ian C. Dec 2 '10 at 18:00
This is looking quite promising - I'll have to play around with it for a few minutes. – thetaiko Dec 2 '10 at 18:31
Exactly what I was looking for, thanks. – thetaiko Dec 2 '10 at 23:28

Not built-in; this sort of thing is generally handled by launchd on OS X, but network up/down events are not on its list of triggers. Fortunately, PyMacAdmin includes a program, crankd, which provides this capability. Here is an example of using crankd to do something similar (although he's using it to launch a Python module rather than a shell script, so the details are a bit different). I haven't tried this, but it looks like you'd just need to create a crankd plist file something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

... then write /usr/local/libexec/networkchangescript to detect whether the network is up (AIUI it'll get launched for any change, whether up, down, or sideways) and set up tunnels if appropriate. Finally, create a launchd plist to run crankd (see the example I linked for details).

share|improve this answer

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