I have a bash script A (i.e. scripta.sh) which executes another bash script B (i.e. scriptb.sh), running other commands.


# Cool logic
scriptb.sh &


# Cool logic
nohup python3 app.py >> app.log &

When I run nohup scripta.sh >> a.log &, I get both the outputs of A and app.py into a.log, while app.log is empty.

Why is this happening? How can I change this behaviour?

  • cannot reproduce; scripta: sh scriptb &; scriptb: nohup echo b >> b.log &; running nohup sh scripta >> a.log &, output is as expected in b.log, while a.log is empty.
    – pLumo
    May 21, 2019 at 15:19
  • @pLumo the OP is probably using "output" as a generic term for the stuff written to both stdout and stderr.
    – user313992
    May 21, 2019 at 15:35
  • @mosvy yes, because apparently I cannot see any difference at the moment. Both errors and output go in that file. I might have to investigate in the behaviour of python output in debug mode.
    – peppe
    May 21, 2019 at 16:03

1 Answer 1


Didn't your nohup say "redirecting stderr to stdout"?

That's exactly what happened. nohup scripta.sh >> a.log & redirected the stderr to a.log (because stderr was a tty when you ran the command from an interactive shell), and then the second nohup python3 .. from scriptb.sh didn't have to do that any more (because its stderr was not a tty, but a.log), and the stderr of python3 ... went to a.log.

This is what the manpage of nohup(1) says:

If standard input is a terminal, redirect it from an unreadable file.

If standard output is a terminal, append output to nohup.out if possible, $HOME/nohup.out otherwise.

If standard error is a terminal, redirect it to standard output.

  • Thanks! Actually I missed a lot of understanding of the problem. So how would you recommend to run the python script in order to save stdout and stderr in a dedicated log file?
    – peppe
    May 21, 2019 at 16:06
  • redirect its stderr explicitly, run it with nohup python app.py >> app.log 2>&1 &
    – user313992
    May 21, 2019 at 16:10

You must log in to answer this question.

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