开发者

How to start multi ssh connection in one bash script?

开发者 https://www.devze.com 2023-02-22 23:19 出处:网络
i have 10+ ssh server needs to do port forwarding when i start to work, but i\'m tired to start those ssh connections one by one. i know in linux the powerful bash script can handle this problem. here

i have 10+ ssh server needs to do port forwarding when i start to work, but i'm tired to start those ssh connections one by one. i know in linux the powerful bash script can handle this problem. here is开发者_StackOverflow中文版 my bash script example

#!/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
....

i found out that if the first ssh connection started, it just stopped at that line and wait it to close.

could any one tell me how to fix it?


Use the -f option:

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

From man ssh:

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


Use can use 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


how about using the screen command?

http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号