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
?
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
.
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.
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.
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
Source: Stackoverflow.com