简体   繁体   English

我可以更改 nohup.out 的名称吗?

[英]Can I change the name of `nohup.out`?

When I run nohup some_command & , the output goes to nohup.out ;当我运行nohup some_command & ,输出转到nohup.out man nohup says to look at info nohup which in turn says: man nohup说要查看info nohup ,它反过来说:

If standard output is a terminal, the command's standard output is appended to the file 'nohup.out';如果标准输出是终端,则命令的标准输出将附加到文件“nohup.out”; if that cannot be written to, it is appended to the file '$HOME/nohup.out';如果无法写入,则将其附加到文件“$HOME/nohup.out”; and if that cannot be written to, the command is not run.如果无法写入,则不会运行该命令。

But if I already have one command using nohup with output going to /nohup.out and I want to run another, nohup command, can I redirect the output to nohup2.out ?但是,如果我已经有一个使用nohup命令,输出到/nohup.out并且我想运行另一个nohup命令,我可以将输出重定向到nohup2.out吗?

nohup some_command &> nohup2.out &

and voila.瞧。


Older syntax for Bash version < 4: Bash 版本 < 4 的旧语法:

nohup some_command > nohup2.out 2>&1 &

For some reason, the above answer did not work for me;出于某种原因,上述答案对我不起作用; I did not return to the command prompt after running it as I expected with the trailing &.运行它后,我没有返回到命令提示符,正如我预期的那样,尾随 &。 Instead, I simply tried with相反,我只是尝试

nohup some_command > nohup2.out&

and it works just as I want it to.它就像我想要的那样工作。 Leaving this here in case someone else is in the same situation.留在这里以防其他人处于相同的情况。 Running Bash 4.3.8 for reference.运行 Bash 4.3.8 以供参考。

Above methods will remove your output file data whenever you run above nohup command.每当您在 nohup 命令之上运行时,上述方法都会删除您的输出文件数据。

To Append output in user defined file you can use >> in nohup command.在用户定义的文件中附加输出,您可以在 nohup 命令中使用>>

nohup your_command >> filename.out &

This command will append all output in your file without removing old data.此命令将在您的文件中附加所有输出,而不会删除旧数据。

As the file handlers points to i-nodes (which are stored independently from file names) on Linux/Unix systems You can rename the default nohup.out to any other filename any time after starting nohup something& .由于文件处理程序指向 Linux/Unix 系统上的 i-nodes(独立于文件名存储)您可以在启动nohup something&后随时将默认nohup.out重命名为任何其他文件名。 So also one could do the following:因此,也可以执行以下操作:

$ nohup something&
$ mv nohup.out nohup2.out
$ nohup something2&

Now something adds lines to nohup2.out and something2 to nohup.out .现在something增加了线路nohup2.outsomething2nohup.out

my start.sh file:我的start.sh文件:

#/bin/bash

nohup forever -c php artisan your:command >>storage/logs/yourcommand.log 2>&1 &

There is one important thing only.只有一件重要的事情。 FIRST COMMAND MUST BE "nohup", second command must be "forever" and "-c" parameter is forever's param, "2>&1 &" area is for "nohup".第一个命令必须是“nohup”,第二个命令必须是“forever”并且“-c”参数是forever的参数,“2>&1 &”区域用于“nohup”。 After running this line then you can logout from your terminal, relogin and run "forever restartall" voilaa... You can restart and you can be sure that if script halts then forever will restart it.运行此行后,您可以从终端注销,重新登录并运行“forever restartall”,瞧……您可以重新启动,并且可以确定,如果脚本停止,则永远将重新启动它。

I <3 forever我 <3 永远

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM