shell scripts in background (with &) - why would they stop?

R

Ruby Baby

Shouldn't a Ruby script keep running if someone uses the "&" at the end of the command?

I have a script that takes hours to run, processing many files, on a remote server.

If I start it like this...
/processFiles.rb
... it will work, but I have to keep an SSH terminal window open for hours.

If I start it like this...
/processFiles.rb &
... and then I close my SSH session to let it run
... it stops immediately after I log out.


Is that expected behavior?

How would I get it to keep running (like my regular /bin/sh shell scripts) after I log out?

I could give example code if someone wants to see it.
 
B

Bermejo, Rodrigo

nohup ./processFiles.rb&
exit

or

ruby -e 'fork do exec("./processFiles.rb&") end'

will make the trick ....

ronnie.
 
G

Gennady

Ruby said:
Shouldn't a Ruby script keep running if someone uses the "&" at the end of the command?

I have a script that takes hours to run, processing many files, on a remote server.

If I start it like this...
./processFiles.rb
... it will work, but I have to keep an SSH terminal window open for hours.

If I start it like this...
./processFiles.rb &
... and then I close my SSH session to let it run
... it stops immediately after I log out.
try:

trap '' 1
/processFiles.rb >processFiles.log 2>&1 &

or with 'nohup', which will do the same for you (redirecting to
nohup.out, though):

nohup ./processFiles.rb &
 
I

Imobach González Sosa

El Martes, 03 de Febrero de 2004 01:02, Ruby Baby escribió:
Shouldn't a Ruby script keep running if someone uses the "&" at the end of
the command?

I have a script that takes hours to run, processing many files, on a remote
server.

If I start it like this...
./processFiles.rb
... it will work, but I have to keep an SSH terminal window open for hours.

If I start it like this...
./processFiles.rb &
... and then I close my SSH session to let it run
... it stops immediately after I log out.


Is that expected behavior?

I'm not sure, but I think no.
How would I get it to keep running (like my regular /bin/sh shell scripts)
after I log out?

Try using the command 'nohup'.
I could give example code if someone wants to see it.

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top