【发布时间】:2016-10-12 22:21:04
【问题描述】:
我没有强大的硬件,所以我不能同时运行多个 ssh 隧道,否则会导致 CPU 负载过高,我的目标是在连接另一个 ssh 隧道后运行,如果我的一个 ssh 断开连接,则重新连接,所以基本上是这样的:
while true; do
if (1st ssh isn't connected); then
connect the first ssh
elif (1st ssh is finally connected); then
run the second ssh
elif (2nd ssh is finally connected); then
run the 3rd ssh
fi
sleep 1
done
问题是 ssh 隧道的数量不断变化,有时用户想运行 3 个 ssh 隧道,有时要运行 5 个,运行脚本看起来像这样:
mytunnel.sh -a [number of tunnels they wanna run]
我正在考虑for loop,但我就是不知道如何在for loop 中编写它。请帮帮我。
【问题讨论】: