I have to start a rather long duration script (it can run for half an hour or more) through SSH, and collect its StdOut/StdErr and return code.
I want to avoid waiting for the process end in the same SSH session because it ties up resources on the server and the session could be closed due to network problems, so the idea is to start the process, disconnect the session and come later to check results.
I thought this would involve nohup
, but if I do this in an ssh session:
(somelongrunningscript.sh >test.out 2>test.err; echo $? >test.rc) & exit 0
The script keeps running after the session is closed. It also keeps running if I don't use a subshell:
somelongrunningscript.sh >test.out 2>test.err & exit 0
(but then I cannot collect the return code).
So why is the script still running without the protection afforded by nohup
? Am I missing something? Am I just lucky?
SIGHUP
? See this answer.nohup
,disown
and&
.