Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What would be the best method of using nohup in a batch script with multiple calls inside the script.

For example, I have a script called and it contains something like:

/usr/bin/python fileA
/usr/bin/python fileB
/usr/bin/python fileC

What I want to do is make ensure that if I run my script, it will continue even if my SSH session is terminated. Should I just call the script like so:


or place nohup before every entry in the file such as:

nohup /usr/bin/python fileA
nohup /usr/bin/python fileB
nohup /usr/bin/python fileC 

or Both? If I place it only on the script, is it possible that one of the python calls could still fail on a termination signal? What is the best practice and which solution will accomplish my requirements? Is there a better alternative?

share|improve this question
up vote 0 down vote accepted

Putting nohup on each line is not the answer.  If you do that, and the session is terminated, the currently-running program will run to completion, but then the script will terminate without finishing.  nohup will work, but then you have to remember to do it every time.  A couple of solutions:

  1. Write to say

    exec nohup

  2. Put

    trap "" 1

at the beginning of your script.  (1 is the numeric value of the “hangup” signal.)

share|improve this answer
thanks for the response. Is that a do both situation or an either or situation for your solutions? – Dave Johnshon Oct 24 '12 at 3:08
@Dave: Either (1) or (2). – Scott Oct 24 '12 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .