Adil
Adil

Reputation: 2112

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 php mylongcommand.php) &> dump

This works, but what if I want to nohup the command so I can check the logs later. The following code does not work:

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

Any suggestions?

Upvotes: 2

Views: 2945

Answers (2)

Politank-Z
Politank-Z

Reputation: 3719

(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. You should be able to exit your shell session without any stopped jobs error, and the process will continue to run.

Upvotes: 3

Fabio A. Correa
Fabio A. Correa

Reputation: 2036

Remove the brackets:

nohup time php mylongcommand.php &> dump &

Upvotes: 0

Related Questions