画面:最近の画面を復元しますか?選択を簡単にしますか?

画面:最近の画面を復元しますか?選択を簡単にしますか?

画面についていくつかの質問があります。と入力すると、screen -r次のメッセージが表示されます。

There are several suitable screens on:
    25154.tracks    (Detached)
    29278.mywork    (Detached)
    29138.mywork    (Detached)
    30915.mywork    (Detached)
    20065.mywork    (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

わかりませんが、しばらく使用しておらず、誤って1つから1つを分離したため、この画面のほとんどは古いものだと思います。これに関する私の質問は次のとおりです。

  • 復元する方法はありますか?最近分割画面?
  • 前の画面セッションを「削除」する方法は?
  • 各セッションの日付と画面数を表示できますか?
  • screen -r簡単に選択できるように、エイリアスを一覧表示された画面に一時的にリンクする方法はありますか?たとえば、一覧表示さscreen -rれた画面が次のような場合は良いでしょう。
There are several suitable screens on:
[1] 25154.tracks  (Detached)
[2] 29278.mywork  (Detached)
[3] 29138.mywork  (Detached)
[4] 30915.mywork  (Detached)
[5] 20065.mywork  (Detached)
Choose  one to resume:

pidこれにより、復元したいフルスクリーンを入力する必要なく、1、2、3、4、または5のみを入力できます。この問題を解決する方法はありますか?

ベストアンサー1

以下はあなたに適したスクリプトです。

#!/bin/bash

function chooser {

    echo
    echo "I found the following screen sessions: "
    echo

    pcount=0

    # 
    # find the session dir
    #
    sessdir=$( screen -ls | egrep 'Socket' | awk '{print $NF}' | sed -e 's/\.$//' )

    #
    # enumerate existing sessions, and add them to the plist() array.
    #
    for screen in $( find $sessdir -type p ); do
            pcount=$((pcount+1))
            pname=$( basename $screen )
            pdate=$( ls -latr $screen | awk '{print "( "$6" "$7" "$8" )"}')
            plist[$pcount]=${pname}
            echo "  [$pcount]       $pname   $pdate"
    done

    echo
    echo -n "Please select a session to reconnect to: "
    read choice

    # 
    # if the selected choice doesn't exist, recycle the chooser.
    #
    if [ -z ${plist[$choice]} ]; then
            echo
            echo "Your choice [$choice] is invalid.  Please try again."
            echo
            sleep 1
            chooser
    else
            screen -r -d ${plist[$choice]}
    fi

}

#
# the chooser function does all the work
#
chooser

現在接続されているセッションとは別のセッションを区別していないため、これが重要な場合は、自分で行う必要があるかもしれません。

おすすめ記事