To use ssh multiplexing for host example.com:
Add the following section to ~/.ssh/config:
Host example.com ControlPath ~/.ssh/control.example.com
The ssh client will now use the socket at the specified ControlPath to create new connections to example.com. A connection will fail if it is attempted and no master connection provides this socket.
Before attempting a connection, use the following script:
if test ! -e ~/.ssh/control.example.com ; then ssh -fMN example.com fi
If the control socket does not exist, this will spawn a master (-M) that executes no command (-N) and goes to the background (-f). If the master is killed with anything nicer than SIGKILL, it will remove the socket. If the master is killed brutally, it is necessary to remove the socket manually.