我没有强大的硬件,因此无法同时运行多个ssh隧道,否则会导致CPU负载过高,我的目标是运行一个SSH隧道另一个连接后,如果我的SSH的一个断开连接重新连接,所以基本上是这样的:Bash脚本 - 如何在连接另一个连接后运行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
内编写它。请帮帮我。