问题
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.
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:
where a = cv000_29590 is the respond from the Matlab. It should keep running
until cv999999 and take about 10 hours.
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.
回答1:
It's not really possible after you've already started a session. But for new sessions you can do the following:
Add the following to the top of your
.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} }Put the following content into
.screenrc:escape ^bb shell -$SHELL termcapinfo xterm ti@:te@ hardstatus lastline "%-Lw[%n%f %t]%+Lw%<" screen -t ${USER}@${HOSTNAME}These are mostly my own customizations of screen. The most important of which is that I set the screen escape character to
CTRL-binstead of the defaultCTRL-aso I can still useCTRL-ain bash to go to the beginning of a line.Use
CTRL-b cto create shells in new windows (or just typenewat the bash prompt to use the function). And useCTRL-b dto 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. UseCTRL-b nto 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.
来源:https://stackoverflow.com/questions/33041892/keep-ssh-sessions-running-after-disconnection