How to keep an SSH tunnel open in MacOS X

Guest Post Blog
Kitt asked me to post this, so here goes: ssh_command_no_exit.sh as follows:
ssh -N -l remoteprocess -L13307:127.0.0.1:3306 -R13307:127.0.0.1:3306 -o ServerAliveInterval=240 re.mo.te.ip
/Library/LaunchDaemons/ssh_tunneler.plist as follows:




   Label
   ssh_tunneler
   ProgramArguments
   
      /path/to/ssh_command_no_exit.sh
   
   OnDemand
   
   Disabled
   


This basically sets up the equivalent of an inittab:respawn on Linux. OnDemand=false indicates that the server should be continuously running. Type in
launchctl load /Library/LaunchDaemons/ssh_tunneler.plist
Finally, launchd kills something that fails within 60 seconds 10 times in a row. If our DSL/cable line goes out, this could take longer. So, add the following line to crontab:
#Re-list the ssh_tunneler
10      0       *       *       0       launchd load /Library/LaunchDaemons/ssh_tunnelr.plist >> /dev/null &2>1