2011-04-06 91 views
3

當我開始工作時,我有10多個ssh服務器需要做端口轉發,但我厭倦了逐一啓動這些ssh連接。我知道在Linux中強大的bash腳本可以處理這個問題。這裏是我的bash腳本示例如何在一個bash腳本中啓動多重ssh連接?

#!/bin/bash 
ssh -L 10001:somehost:3306 [email protected] -N 
ssh -L 10002:somehost:3306 [email protected] -N 
ssh -L 10003:somehost:3306 [email protected] -N 
.... 

我發現,如果第一個SSH連接開始,它只是停在那條線,並等待它關閉。

任何人都可以告訴我如何解決它?

回答

4

使用-f選項:

ssh -f -N -L 10001:somehost:3306 [email protected] 

man ssh

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

爲-f工作運行的SSH命令我。謝謝!@eugene y – opps 2011-04-06 09:30:54