Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have connected to my server via SSH and created a process, but suddenly my internet connection got disconnected. I know that the process is going on, but how can restore previous session to see the progress of it?

share|improve this question

7 Answers 7

up vote 16 down vote accepted

As suggested above, in the future you can use screen to prevent such thing. A short explanation on how to use screen:

  1. screen -S compiling_stuff
  2. Do stuff here. e.g ./configure
  3. If connection is closed for some reason you can reconnect to the server and issue screen -r comp
  4. You can detach the screen session yourself too by pressing CTRL+A+D

Good luck

share|improve this answer

screen is the best to start a command in a terminal that will be kept when you disconnect from it (either on purpose, ctrl+a d, or because connection dies, etc).

HOWEVER you CAN re-attach a running process (ex: the shell of your running session, if still running) to your current terminal (ie, re-attach stdin, stdout, keyboard, but also make the new terminal the controlling terminal for that process) using: reptyr

For the best of both worlds: install screen, start it, and then re-attach that process in that screen sessions with reptyr ^^

share|improve this answer
    
Oliver, how is it possible to re-attach to running process? Could you gimme a hint please? –  archer Jan 11 '13 at 15:12
    
@archer : hint : follow the link ^^ (end of my 2nd paragraph) –  Olivier Dulac Jan 11 '13 at 17:02
    
@archer : but screen is simpler: once runnign in screen, ctrl+a d : detach from screen (and go home). then to re-attach to screen: "screen -r" (or a more complex way, if things get stuck). To differentiate amongst many screen sessions, give them a name. –  Olivier Dulac Jan 11 '13 at 17:06
    
thanks alot. I'm trying reptyr now. –  archer Jan 11 '13 at 17:40

You can't. In the future, you can prevent something like this with using screen or tmux, which where created to allow to reconnect to a session after a disconnect.

share|improve this answer

Just thought I would mention http://mosh.mit.edu/

Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes.

Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links.

share|improve this answer
    
+1 for the heads up, I never heard of that tool before! –  Olivier Dulac Jan 21 '13 at 13:30

Use screen via ssh to reconnect later to your session.

As far as I know there is no way to reconnect to a closed ssh-session.

share|improve this answer

I can recommend Byobu:

Byobu is an enhancement for the terminal multiplexers GNU Screen or tmux that can be used to provide on screen notification or status as well as tabbed multi window management. It is aimed at providing a better user experience for terminal sessions when connecting to remote servers.

share|improve this answer

I would recommend to use tmux:

You can restore tmux session via tmux attach.

tmux is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command line interface, and for separating programs from the Unix shell that started the program.[1] It provides many of the same functions as GNU Screen, but is distributed under a BSD license.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.