Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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, Diago 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

2 Answers 2

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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>SystemConfiguration</key>
    <dict>
        <key>State:/Network/Global/IPv4</key>
        <dict>
            <key>command</key>
            <string>/usr/local/libexec/networkchangescript</string>
        </dict>
    </dict>
</dict>
</plist>

... 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 or ask your own question.