
제가 실행하는 프로그램이 있는데 mdr-dev
그 결과 포트 1022가 열립니다.
해당 포트를 연 후에 해당 포트를 열린 상태로 유지하려면 프로그램을 실행 상태로 두어야 합니다. 문제는 실행하는 데 시간이 좀 걸리므로 그 동안 해당 포트가 열릴 때까지 기다려야 한다는 것입니다!
포트가 열리면 새 터미널을 열고 ssh
해당 포트를 통해 원격 장치로 연결하고 싶습니다.
문제는 이것에 대해 bash나 다른 스크립트를 작성하는 방법입니다.
(이미 sleep 명령으로 시도했지만 작동하지 않는 것 같습니다.)
지금까지 시도한 내용은 다음과 같습니다.
#!/bin/bash
echo $MDR_ROOT
mdr-dev --root --mount /opt/tile/home /home --tunnel 1022 22
위 명령의 초기화 프로세스 후에 mdr-dev
자동으로 새 터미널을 열고 다음을 실행하고 싶습니다.
ssh -p 1022 root@localhost
물론, 나는 이미 다음을 시도했습니다.
--tunnel 1022 22 &
sleep 5m
xterm -hold -e ssh -p 1022 root@localhost
그런데 그게 안되는 것 같더라구요...
어떻게 진행해야 하나요?
답변1
귀하의 프로그램이 없기 때문에 mdr-dev
이것을 테스트하기가 어렵습니다. 그래서 여기에 버전 0.1이 있습니다. 테스트해보고 댓글로 피드백 부탁드립니다.
#!/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