Per default, nohup
writes stdout
to nohup.out
and dismisses stderr
. I would like to have it the other way around:
write stderr
to a file and dismiss stdout
.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityYou can do it like this:
nohup command 2>&1 >/dev/null &
Because the first redirect is from STDERR to current handler of STDOUT
it write to nohup.out
. Then STDOUT
is redirected to NULL
Just redirect standard error to the file you want:
$ ls
test.sh
$ cat test.sh
#!/bin/bash
echo "out"
echo "error" 1>&2
$ ./test.sh
out
error
$ nohup ./test.sh < /dev/null > /dev/null 2> err.out
$ ls
err.out test.sh
$ cat err.out
error
From the manual:
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. To save output to FILE, usenohup COMMAND > FILE
.
Given that it is silent if stderr is redirected, it stands to reason that it would behave normally, and, as shown above, it does.