【发布时间】:2011-01-15 12:17:09
【问题描述】:
在 Cygwin 上,我想要一个 Bash 脚本:
- 创建到远程服务器的 SSH 隧道。
- 在本地做一些使用隧道的工作。
- 然后关闭隧道。
关机部分让我很困惑。
目前,我有一个蹩脚的解决方案。在一个 shell 中,我运行以下命令来创建隧道:
# Create the tunnel - this works! It runs forever, until the shell is quit.
ssh -nNT -L 50000:localhost:3306 jm@sampledomain.com
然后,在另一个 shell 窗口中,我做我的工作:
# Do some MySQL stuff over local port 50000 (which goes to remote port 3306)
最后,完成后,我关闭第一个 shell 窗口以终止隧道。
我想在一个脚本中完成所有这些操作,例如:
# Create tunnel
# Do work
# Kill tunnel
我如何跟踪隧道进程,以便知道要杀死哪个进程?
【问题讨论】:
-
我写了一个脚本来帮助做 ssh 隧道,你可以查看:github.com/gdbtek/ssh-tunneling.git