Skip to main content

How to get nohup to exit cleanly when using file redirect [Resolved]

Using the following command:

nohup tail -f file | stdbuf -o0 awk '/string1/ && /string2/' > file &

This creates data in my file which is what I want but this also gives me the following:

[2] 13717
[root@server]# nohup: ignoring input and redirecting stderr to stdout

From there I have to ctrl-c to get back to a prompt. What do I need to change to get back to a prompt?

Asked March 20, 2017
Posted Under: Unix Linux
1 Answers

You actually have a prompt. What is happening is that you are getting it before nohup reports its warnings about stdin and stdout. If you type a command, it will run just as you would expect it to notwithstanding the visually unorthodox apparent expansion to your prompt.

If this is truly offensive to your sensibilities, you can work around it with a subshell:

$ (nohup stuff and things > logfile & ) > /dev/null 2>&1

Alternatively, you can address the warnings. You are being warned because you are not handling standard input and standard error. If you handle them yourself, nohup has nothing to change and so it will be silent:

$ nohup stuff and htings > logfile 2> errfile < /dev/null &

If you do not want to capture standard error, you can use /dev/null for your error file; if you want it to go to the same place as standard output, you can use 2>&1.

Answered March 20, 2017
Lol, yes, it is VERY offensive to my sensibilities. – user53029 19 mins ago
 CanDoerz  1 month ago
Is there any way to have it exit cleanly? – user53029 21 mins ago
 CanDoerz  1 month ago
Your Answer