Can I change the name of `nohup.out`?

BashLoggingNohup

Bash Problem Overview


When I run nohup some_command &, the output goes to nohup.out; man nohup says to look at info nohup which in turn says:

> If standard output is a terminal, the > command's standard output is appended > to the file 'nohup.out'; if that > cannot be written to, it is appended > to the file '$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?

Bash Solutions


Solution 1 - Bash

nohup some_command &> nohup2.out &

and voila.


Older syntax for Bash version < 4:

nohup some_command > nohup2.out 2>&1 &

Solution 2 - Bash

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.

Solution 3 - Bash

Above methods will remove your output file data whenever you run above nohup command.

To Append output in user defined file you can use >> in nohup command.

nohup your_command >> filename.out &

This command will append all output in your file without removing old data.

Solution 4 - Bash

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&. 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.

Solution 5 - Bash

my start.sh file:

#/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". 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.

I <3 forever

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid LeBauerView Question on Stackoverflow
Solution 1 - BashismailView Answer on Stackoverflow
Solution 2 - BashGodsmithView Answer on Stackoverflow
Solution 3 - BashIrshad KhanView Answer on Stackoverflow
Solution 4 - BashTrueYView Answer on Stackoverflow
Solution 5 - BashkodmanyaghaView Answer on Stackoverflow