I am using Putty to connect to a remote server. What I want to know is if there is any way to write my commands and allow them to keep running after I close the session with Putty. The reason for this is that I do not want to keep the computer ON all the time. Is there any way to do this?.
Update with the solution
For my question as it is presented the best solution is use one of the commands provided such as nohup, because you do not have to install any additional software. But if you are in the same problem use screen, install it and use it. It is amazing.
I have selected the answer of Norman Ramsey as favourite because propose several solutions using commands and screen. But please check the other answers specially the one of PEZ, then you get an insight of what screen is able todo.
Duplicated question: stackoverflow.com/questions/285015
Possible duplicate of In Linux, how to prevent a background process from being stopped after closing SSH client, How to make a program continue to run after log out from ssh?, etc.
One way that works well for me is
at
.at
works like cron, but for a one-time job. I used it today to download a large file without having to keep my session alive.for example:
You pass
at
a time (in the future) and it gives you a prompt. You enter the commands you want to run at that time and hit ctrl+d. You can exit out of your session and it will run the commands at the specified time.Wikipedia has more info on
at
.What you are looking for is nohup.
See the wiki link for how to use it.
Try using GNU Screen. It allows you to have several shells open at once. And you can disconnect from those running shells (i.e. close session with Putty) and they will keep doing their thing.
nohup
,disown
, andscreen
are all good butscreen
is the best because unlike the other two,screen
allows you to disconnect from the remote server, keep everything running, and then reconnect later to see what is happening. Withnohup
anddisown
you can’t resume interacting.If you can’t use
screen
(because, for instance, your SSH session is being programmatically driven), you can also use daemonize to run the program as a daemon.screen! It’s the best thing since sliced bread. (Yeah, I know others have already suggested it, but it’s so good the whole world should join in and suggest it too.)
screen is like, like, ummmm … like using VNC or the like to connect to a GUI destop, but for command shell windows. You can have several shell “windows” open at once in the same screen session. You can do stuff like:
It’s like magic. I’ve been using screen for longer than I can remember and I’m still totally amazed with how bloody great it is.
EDIT: Just want to mention there’s now also tmux. Very much like screen, but has some unique features, splitting the windows being the most prominent one.
screen
is the best.Try:
This start command in background.
Use
screen -r
to list, and orscreen -r
Mytail to enter session.If more users need access same session, use: screen -rx MyTail, and both or more users share the session.