简体   繁体   English

如何“ nohup”命令并记录“ time”的输出

[英]How can I 'nohup' a command and log the output of 'time'

I want to time a long running script, and log the output of the time command to a log file, like so: 我想给长时间运行的脚本计时,并将time命令的输出记录到日志文件中,如下所示:

(time php mylongcommand.php) &> dump

This works, but what if I want to nohup the command so I can check the logs later. 这工作,但如果我想nohup命令,所以我可以稍后检查日志。 The following code does not work: 以下代码不起作用:

nohup (time php mylongcommand.php) &>dump &

Any suggestions? 有什么建议么?

(time php mylongcommand.php) &> dump < /dev/null &

Should also do the trick. 还应该做到这一点。 By redirecting input from /dev/null and using & to put the process into the background, the same effect is obtained as if you used nohup . 通过从/dev/null重定向输入并使用&将进程置于后台,可以获得与使用nohup相同的效果。 You should be able to exit your shell session without any stopped jobs error, and the process will continue to run. 您应该能够退出shell会话而不会出现任何已停止的作业错误,并且该过程将继续运行。

卸下支架:

nohup time php mylongcommand.php &> dump &

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

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