2

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!

mfinni
  • 35,711
  • 3
  • 50
  • 86
Eugeny89
  • 131
  • 1
  • 5

3 Answers3

10

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.

Michael Lowman
  • 3,584
  • 19
  • 36
5

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.

mfinni
  • 35,711
  • 3
  • 50
  • 86
4

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.

Scrivener
  • 3,106
  • 1
  • 20
  • 23
  • 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