On CYGWIN, I want a BASH script to:
- create an SSH tunnel to a remote server.
- Do some work locally that uses the tunnel.
- Then shutdown the tunnel.
The "shutdown part" has me perplexed.
Currently, I have a lame solution. In one shell I run the following to create a tunnel.
# Create the tunnel - this works! It runs forever, until shell is quit.
ssh -nNT -L 50000:localhost:3306 [email protected]
Then, in another shell window, I do my work
# Do some MYSQL stuff over local port 50000 (which goes to remote port 3306)
Finally, when I am done. I close the first shell window to kill the tunnel.
I'd like to do this all in one script like: # Create tunnel # do work # Kill tunnel
How do I keep track of the tunnel process, so I know which one to kill?