Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I'm trying to write a shell script that does a lengthy batch job on a remote server. I'll be running the script over SSH.

The thing is, I intend to start the script in the evening and collect the results the next morning; I'd prefer not to have my local computer have to run all night, as it's not needed as part of the batch process. As such, is there a way I can close the SSH connection and still have the shell script continue to run on the remote server?

share|improve this question

marked as duplicate by slm, Anthon, jasonwryan, rahmu, Renan Nov 18 '13 at 10:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You can run the script within tmux or screen and reconnect later. –  Anthon Nov 17 '13 at 20:37

2 Answers 2

up vote 0 down vote accepted

Yes, if you start the script to run in the background, it will continue to run. Alternately, you can start the script by using the command on command-line. For example, you can say:

ssh hostname -l loginname command

and that will work.

share|improve this answer
1  
"Yes, if you start the script to run in the background, it will continue to run." -> Not if there's a process in there that closes automatically when it finds stdin closed. That's the major reason nohup exists, I think. –  goldilocks Nov 17 '13 at 21:24
    
It certainly continued to run for me. Thank you! –  SoItBegins Nov 18 '13 at 11:25

One way to do this would be to use nohup. Here is an example:

nohup your_prog.sh &

This will run the program called your_prog.sh in the background with & and redirect all the outputs to a file called nohup.out.

Now, you can monitor the output of the program running in the background by using a command like:

tail -f nohup.out

The program that is started with the nohup command will continue to run until terminated by a reboot or an explicit kill command (or until your program exits).

share|improve this answer
    
This question was asked and answered here –  user52540 Nov 17 '13 at 22:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.