Como não tenho seu programa mdr-dev
, é difícil testar isso, então aqui vai a versão 0.1. Por favor, teste e feedback nos comentários.
#!/bin/bash
#
# This script opens a port to tunnel through, then waits for the tunnel to be opened
# and then connects to the correct host using ssh
# Answer to: https://sobrelinux.info/questions/181279/how-to-wait-for-a-while-and-then-suspend-current-work-on-open-new-terminal-in-a""
if $bDebug ; then
set -x
declare iDebugTimeOut=30 #seconds
fi
### Main ###
echo "$MDR_ROOT"
# open tunnel:
mdr-dev --root --mount /opt/tile/home /home --tunnel 1022 22 &
if $bDebug ; then
read -t $iDebugTimeOut -p "Hit [Enter] to continue..."
fi
#Wait for the tunnel to open
while [ -z "$szPortOpen" ]
do
sleep 1m
netstat -atn | grep ":1022" | (read szPortOpen; )
if $bDebug ; then
echo $szPortOpen
read -t $iDebugTimeOut -p "Hit [Enter] to continue..."
fi
done
# Now ssh to the server
xterm -hold -e ssh -p 1022 root@localhost