断开连接后保持SSH会话运行 [英] Keep SSH Sessions running after disconnection

查看:29
本文介绍了断开连接后保持SSH会话运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过外壳终端使用笔记本电脑登录学校的服务器以运行Matlab会话.该课程大约需要10个小时,我想结束我的会议笔记本电脑,回家,吃晚饭,然后重新接合外壳终端以检查Matlab会话的进度.

I am using my laptop via shell terminal to log on school’s server to run a Matlab session. The session will take about 10 hours and I want to close my laptop, go home, have dinner, and re-engage the shell terminal to check the progress of my Matlab session.

通过此链接,我知道我应该使用nohup nohup 使我的终端保持活动状态,但我遇到以下问题.这是我启动后的外壳截图运行Matlab会话:

From this link I know I should use nohup nohup to keep my terminal alive, but I meet the following problem. Here is a screenshot of my shell after I start running Matlab session:

其中 a = cv000_29590 是来自Matlab的响应.它应该继续运行直到 cv999999 大约需要10个小时.

where a = cv000_29590 is the respond from the Matlab. It should keep running until cv999999 and take about 10 hours.

问题是,此外壳不再是交互式的.我无法输入命令,即我无处输入 nohup 来保持我的SSH命令会话仍然存在.

The problem is, this shell is not interactive anymore. I can’t enter anymore commands, that is, I have no where to enter nohup commend to keep my SSH session alive.

推荐答案

在开始会话后,这实际上是不可能的.但是对于新的会话,您可以执行以下操作:

It's not really possible after you've already started a session. But for new sessions you can do the following:

  1. 将以下内容添加到 .bash_profile 的顶部:

if [ -z "${PS1}" ] ; then
    return
fi

if [ "${TERM}" != "screen" ] ; then
    export HOSTNAME
    exec screen -xRR
fi

function new {
    u=${1:-$USER}
    test ${u} = ${USER} && screen -t ${u}@${HOSTNAME} || screen -t ${u}@${HOSTNAME} su --login ${u}
}

  • 将以下内容放入 .screenrc :

    escape ^bb
    shell -$SHELL
    termcapinfo xterm ti@:te@
    hardstatus lastline "%-Lw[%n%f %t]%+Lw%<"
    screen -t ${USER}@${HOSTNAME}
    

    这些主要是我自己对屏幕的自定义.其中最重要的是我将屏幕转义字符设置为 CTRL-b 而不是默认的 CTRL-a 所以我仍然可以使用 CTRL-a转到一行的开头.

    These are mostly my own customizations of screen. The most important of which is that I set the screen escape character to CTRL-b instead of the default CTRL-a so I can still use CTRL-a in bash to go to the beginning of a line.

    使用 CTRL-b c 在新窗口中创建外壳(或只需在bash提示符下键入 new 即可使用该功能).并使用 CTRL-b d 断开会话并使其运行.下次登录时,您将重新连接到会话,一切将保持原样.使用 CTRL-b n 循环浏览您创建的窗口.如果您不想使用多个窗口,则不必这样做,只需使用保持会话运行并稍后重新连接的功能即可.

    Use CTRL-b c to create shells in new windows (or just type new at the bash prompt to use the function). And use CTRL-b d to detach your session and leave it running. Next time you login, you'll be reattached to your session and everything will be as it was. Use CTRL-b n to cycle through the windows you've created. If you don't want to multiple windows, you don't have to, just use the ability to leave a session running and reattach later.

    这篇关于断开连接后保持SSH会话运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆