bash スクリプトでしばらく待ってから新しいターミナルを開いて現在の作業を一時停止する方法

bash スクリプトでしばらく待ってから新しいターミナルを開いて現在の作業を一時停止する方法

というプログラムを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

関連情報