当我开始工作时,我有10多个ssh服务器需要进行端口转发,但我已经厌倦了逐个启动这些ssh连接。我知道在Linux中强大的bash脚本可以处理这个问题。这是我的bash脚本示例
#!/bin/bash
ssh -L 10001:somehost:3306 user@host1 -N
ssh -L 10002:somehost:3306 user@host2 -N
ssh -L 10003:somehost:3306 user@host3 -N
....
我发现如果第一个ssh连接启动,它就会停在该行并等待它关闭。
任何人都可以告诉我如何解决它吗?
答案 0 :(得分:5)
使用-f
选项:
ssh -f -N -L 10001:somehost:3306 user@host1
来自man ssh
:
-f Requests ssh to go to background just before command execution.
答案 1 :(得分:0)
使用可以使用nohup;)
#!/bin/sh
nohup ssh -L 10001:host:3306 user@host1 -N
nohup ssh -L 10002:host:3306 user@host2 -N
nohup ssh -L 10003:host:3306 user@host3 -N
答案 2 :(得分:-1)