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'm newby so the question is simple. After I connected to server via putty I want to execute some command. Suppose that command will be performed for long time (e.g. extracting files from large archive or mysql backup). Is there a way to execute a command in such a way that it wount be aborted after I close putty!

thank you in advance!

share|improve this question

3 Answers 3

up vote 10 down vote accepted

The best way is to run screen, execute your command, then detach using ^A, D. When you ssh into your machine again, run screen -r and your session will be reattached just as you left it. Screen can also do much more, check out the man page to see what's possible.

share|improve this answer
    
Prefer tmux, but much the same idea. –  84104 Jun 17 '11 at 20:32

There's a package called "screen" that needs to be installed on the host you're logged into. This has nothing to do with putty, or ssh - this is the way Unix shells work. When you disconnect a shell, you're logged off, and all your processes get a HUP signal. Most (all) processes shut down. "Screen" makes your shell continue running, so you may reconnect later.

share|improve this answer

Yes! You should background the process and disown it.

So, if I wanted to run the command "foo", I'd do nohup foo & && disown. The nohup keeps it from dying when SIGHUP is sent to it and sends the output to a file, and disown removes the parent reference so it doesn't die when the spawning shell does.

share|improve this answer
    
This will work as well, although you won't be able to interact with it and hopefully can get everything you need out of the logfile. –  mfinni Jun 17 '11 at 16:38

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.