在我的服务器上 nohup sleep 1 > nohup.out &
没有提供帮助信息。很好。
在我的笔记本电脑上运行相同的命令,我得到:nohup: ignoring input and redirecting stderr to stdout
。虽然该命令仍然运行并正确完成,但我不明白为什么我的两台机器在报告此消息时存在差异。不过,幸运的是,我可以通过简单地将 stderr 和 stdout 重定向到一个文件来解决我笔记本电脑上的这个问题:nohup sleep 1 &> nohup.out &
所以....我想做的是在我的笔记本电脑上执行一个更有用的命令:
以下在我的服务器上工作正常,没有报告任何消息:
nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find\1 %"| sh > nohup.out &
这行代码“nohups”将文件的管道列表“nohups”到 sed 中,在那里它们通过 script.pl
连续运行并在 shell 中执行。 script.pl
将数据打印到多个文件,并将一些信息打印到标准输出。我通过将其写入名为 nohup.out
现在,当我在笔记本电脑上运行这个单行程序时,我得到 nohup: ignoring input and redirecting stderr to stdout
。这是预期的(但出于我不知道的原因)。但是当我修改该行以重定向 stderr 和 stdout 时:
nohup ls -1 *.txt | sed -e "s%\(.*\)%/home/user/scripts/script.pl -find\1 %"| sh &> nohup.out &
我仍然收到消息 nohup: ignoring input and redirecting stderr to stdout
如何修复我的 one-liner,使其在笔记本电脑上运行时不会收到显示的消息?
最佳答案
我这可能对你有用:
nohup ls -1 *.txt 2>/dev/null | .....
原因是 nohup
向 stderr
发出警告消息,因此将 stderr
指向无处 2>/dev/null
抛弃它。
关于bash - nohup 和 sed,重定向 stderr 和 stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426392/