I found myself wanting to launch and control a port-forwarding ssh session from
a shell script today and I eventually figured out how to do it.
The tricky part was that I also wanted the script to do other things (start a
Selenium server) and kill off the ssh connection when it was done.
The Code
How it works
The SSH command is the trickiest bit, so here it is, more in depth.