Saving nohup output to a file other than nohup.out

Shell : bash
OS : Oracle Linux 6.4

I want to save the ouput of a nohup command to file other than nohup.out . Below are my 3 attempts.

For both Attempt1 and Attempt2 , the redirection logs the output correctly to the output file. But I get the error "ignoring input and redirecting stderr to stdout" in the shell just after the nohup command is issued.

I tried Attempt3 with 2>&1. This one also logged to output file. This time I didn't get the error "ignoring input and redirecting stderr to stdout" . But I got "nohup: ignoring input" as the first line in the error log.

How can I get an error-less redirection of nohup output file ?

I am creating a formal document detailing steps for a critical activity. Althoug the below executions work fine , I want to get rid of those ignorable errors. Any idea how I can get rid of those errors ?

$ cat test.sh
#!/bin/bash
echo -e "hello world Start"
sleep 10
echo -e "hello world End"
mumbojumbo
$

## Attempt1.

$
$ nohup test.sh >MyOutput.log &
[1] 6535
$ nohup: ignoring input and redirecting stderr to stdout

$
$ cat MyOutput.log
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found
[1]+  Exit 127                nohup test.sh > MyOutput.log

### Attemp2 (a space after the redirection character > )

$ nohup test.sh > MyOutput.log &
[1] 9914
$ nohup: ignoring input and redirecting stderr to stdout

$
$ cat MyOutput.log
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found
[1]+  Exit 127                nohup test.sh > MyOutput.log

Attempt3. using 2>&1

$ nohup test.sh > MyOutput.log 2>&1 &
[1] 11773
$
$
$
$
$ cat MyOutput.log
nohup: ignoring input
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found

Try redirecting stdin from /dev/null.

1 Like

Redirect stdin to get rid of the last error:

nohup test.sh > MyOutput.log 2>&1 </dev/null &
1 Like
nohup test.sh &>MyOutput.log &
1 Like

Thank you Cero, RudiC

Cero's (and RudiC's) solution has worked

nohup test.sh > MyOutput.log 2>&1 </dev/null &

But I didn't quite understand how 'redirecting stdin from /dev/null' work.

Regarding commands to accept Standard Input: I've only used things like below in my career.
sort < unsorted_names_list.txt

And I have only bit bucket /dev/null to discard errors like below.
find / -name "HelloWorld" 2>/dev/null

Can you explain how redirecting stdin from /dev/null got rid of the error ?

man nohup :

1 Like

Thank you RudiC.

But , what does re-directing input from /dev/null even mean ?

$ wc < /dev/null
      0       0       0
$
$
$ echo < /dev/null

$

nohup ensures that the process will continue even if the user logs out, which means the user's terminal and thus stdin is lost. I think that "ignore" message results from nohup trying to become independent from the interactive stdin which you assist by redirecting from /dev/null.