
Tengo un programa llamado mdr-dev
que ejecuto y que como resultado abre el puerto 1022.
Después de abrir ese puerto, tengo que dejar el programa ejecutándose para mantener ese puerto abierto. El problema es que lleva algo de tiempo ejecutarlo, así que mientras tanto debo esperar a que abra ese puerto.
Una vez que el puerto está abierto, quiero abrir una nueva terminal y, ssh
a través de ese puerto, acceder a un dispositivo remoto.
La pregunta es: ¿Cómo escribir un bash o cualquier otro script para esto?
(Ya lo intenté con el comando de suspensión pero no parece funcionar).
Esto es lo que he probado hasta ahora:
#!/bin/bash
echo $MDR_ROOT
mdr-dev --root --mount /opt/tile/home /home --tunnel 1022 22
Después del mdr-dev
proceso de inicialización del comando anterior, quiero abrir automáticamente una nueva terminal y ejecutar:
ssh -p 1022 root@localhost
Por supuesto, ya lo intenté:
--tunnel 1022 22 &
sleep 5m
xterm -hold -e ssh -p 1022 root@localhost
pero eso no parece funcionar...
¿Cómo debo proceder?
Respuesta1
Como no tengo tu mdr-dev
programa, me resulta difícil probarlo, así que aquí va la versión 0.1. Pruebe y comente en los comentarios.
#!/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: http://askubuntu.com/questions/682316/how-to-wait-for-a-while-and-then-suspend-current-work-on-open-new-terminal-in-a
# Copyright (c) Fabby 2015
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. See the GNU General Public License for more details.
# You DID NOT receive a copy of the GNU General Public License along with this program as the license is bigger then this program.
# Therefore, see http://www.gnu.org/licenses/ for more details.
# version 0.1 dd 2015-10-08 First version.
### Init ###
declare -r bDebug=false
declare szPortOpen=""
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