2

nohup automatically redirects stderr to stdout, but I want to send it to the terminal (it shows progress). How can I do that?

IttayD
  • 381

2 Answers2

3

Just redirect it. Take this script, for example which prints a line to stderr and one to stdout:

#!/bin/sh
echo stderr >&2
echo stdout

If I now run that with nohup and redirect standard error to a file, it works as expected:

$ nohup a.sh 2>er
$ cat er
nohup: ignoring input and appending output to ‘nohup.out’
stderr

Note that it also includes the stderr of nohup itself since you are redirecting output of the nohup. You can do the same with stdout:

nohup a.sh > foo

Basically, nohup only uses nohup.out when you don't redirect output.


To print stderr to the terminal, you can use process redirection to pass stderr through tee:

$ nohup a.sh 2> >(tee)
nohup: ignoring input and appending output to ‘nohup.out’
stderr
terdon
  • 242,166
1

As nohup manual states:

NAME
   nohup - run a command immune to hangups, with output to a non-tty

It is used to run a command WITHOUT a tty asociated with it, you can end your session and the command will keep running, thus its output is not attached to a tty therefore not being able to show the output there. nohup creates a file named nohup.out though, you can access that file with tail -f from any terminal and keep whatching the command's output.

YoMismo
  • 4,015