Web Hosting Talk







View Full Version : Keeping a program executed after leaving ssh session?


dallassmith
08-26-2002, 06:53 PM
How do I keep a file to keep running when I exit out of an ssh session so the program keeps running?

lotuslnd
08-26-2002, 07:25 PM
just type "nohup <command to execute>"

so, if i'm running a script called checkout.pl, and i want to it continue whether or not i log out or my connection drops or whatever, i'd type:

> nohup checkout.pl

cool?

Gernot
08-26-2002, 07:27 PM
You could also do this:

/path/to/command.sh &

Wazeh
08-26-2002, 08:07 PM
If the program requires the terminal access, it will stop execution. You can run screen to keep your processes running safely when you logout. It help also to keep your session intact if you get disconnected from the net for some reason.

tribby
08-26-2002, 08:15 PM
/path/command &

is what I do.

clockwork
08-26-2002, 09:15 PM
'man screen'

screen works better (IMO) than just sending it into the background... since you can easily use 'screen -r' (especially useful for interactive programs)

StarGate
08-26-2002, 09:42 PM
nohub indeed, that's the one

fog
08-26-2002, 10:31 PM
nohup, not nohub. :) (Although hopefully you'll have all switches and no hubs... ;) )

I typically just append the "&" to run it in the background, but I'd guess that nohub/screen are probably "more correct"

zdwebhosting
08-26-2002, 11:13 PM
i use screen myself

no1v2
08-27-2002, 02:44 AM
If it's interactive use screen, but if it's not then just use & (as Gernot described it). There's no real point to using screen for a daemon.

MarlboroMan
08-27-2002, 03:38 AM
Yes, but my understanding is, if you simply background a process with &, it's still attached to your terminal, and will be killed if your terminal disconnects, eg, network outage or similar. If it's something that absolutely has to be ran and not interuppted the first time, then I screen it. It's not that hard to de-attach/re-attach screens.

lotuslnd
08-27-2002, 05:41 AM
^^^ correct ... logging out kills existing & jobs.

no1v2
08-27-2002, 05:43 AM
That's pretty weird, I've heard & read that same thing many times. I've probably used & to run processes in the background hundreds of times by now, on many different servers (running different types of unix as well), and its worked every time :eek: Originally I tried to figure out what was going on, but then I thought "What the hell, if it works I'll use it."

Gernot
08-27-2002, 06:20 AM
Originally posted by MarlboroMan
Yes, but my understanding is, if you simply background a process with &, it's still attached to your terminal, and will be killed if your terminal disconnects, eg, network outage or similar. If it's something that absolutely has to be ran and not interuppted the first time, then I screen it. It's not that hard to de-attach/re-attach screens.

No, if you use & it's not attached to your terminal but you still get the output of this program. If you log out after running a command with &, that process still continues running until it's finished.
& is my favorite because it's so simple to use and there's, in most cases, no need to take the complicated approach by using nohup :)

fog
08-27-2002, 03:40 PM
I agree, I can start somethign with "&" and log out, and it keeps going. (Though forcibly killing the terminal closes it. Does bash come with a script or something that will move things to "screen" or "nohup"?)

AnonymousCow
08-28-2002, 12:58 PM
nohup usage:
nohup [command]

Apparently, if you use the C-shell, before you logout.. just type "nohup" and it should save all the currently running processes of your shell. Shame that the C-shell is (otherwise) a horror to work with :(

I recommend just using 'screen', run it when you login.. and forget about it. Screen has a bunch of other nice things like copy/paste, multiple virtual windows (full or split-screen modes), etc.