屏幕:恢复最近的屏幕?让选择更容易?

Modified on: Sat, 30 Jun 2018 08:03:00 +0800

我对屏幕有几个问题:
当我输入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.

我不确定,但我相信大多数这些屏幕都是旧的,因为我有一段时间没有使用过屏幕,而我只是意外脱离了屏幕。有了这个,我的问题是:

  • 有没有办法恢复最近分离的屏幕?
  • 如何“删除”较旧的屏幕会话?
  • 是否可以在每个会话中显示日期和屏幕数量?
  • 有没有办法暂时将别名关联到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:

然后我可以输入1,2,3,4或5而无需键入我要恢复的屏幕的完整pid。有什么可以做到的吗?

最佳答案

这是一个适合您的脚本。

#!/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

我没有区分当前附加或分离的会话,因此如果对您来说重要,您可能必须自己这样做。

作者:,Tim Kennedy

相关问答

添加新评论