Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在一个bash脚本中启动多ssh连接?_Bash_Ssh - Fatal编程技术网

如何在一个bash脚本中启动多ssh连接?

如何在一个bash脚本中启动多ssh连接?,bash,ssh,Bash,Ssh,当我开始工作时,我有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连接启动,它只

当我开始工作时,我有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连接启动,它只会在该行停止并等待它关闭

谁能告诉我怎么修吗?

使用可以使用nohup;)


使用screen命令怎么样


使用
-f
选项:

ssh -f -N -L 10001:somehost:3306 user@host1
manssh

-f      Requests ssh to go to background just before command execution.

感谢您的回答,但我希望在一个脚本中运行这些ssh命令
-f      Requests ssh to go to background just before command execution.