Is it possible for nohup to write the output both to the file nohup.out AND to the screen/terminal?
Solution 1
You can run
nohup yourprocess & tail -f nohup.out
Solution 2
Proof.
nohup yourprocess 1>&2 | tee nohup.out &
Related videos on Youtube
eikonal
Updated on September 18, 2022Comments
-
eikonal over 1 year
I am using the
bash
shell. I frequently usenohup
to ensure that my processes are not stopped when I close the shell/terminal that started them. I use a syntax like:nohup myprocess
When starting,
nohup
gives the message:nohup: ignoring input and appending output to 'nohup.out'
Then,
nohup
gives no more output to the screen; it is all written tonohup.out
.Frequently, however, I would like to monitor the progress of my computation. I can do this by reading
nohup.out
usingvi
ortail
, but this can be time consuming to do a lot, especially when my computations take several hours.Is there any way that I can print the output to both
nohup.out
(in case I lose internet connection and thus the terminal that started the process is closed) and to the screen? Thanks for your time.-
derobert over 11 yearsHave you considered using
screen
ortmux
instead of nohup? -
eikonal over 11 years@derobert Thanks. I have
screen
on my system, but I have never used it. I don't havetmux
on my system, but I can try to get it. -
jw013 over 11 yearsJust launch
screen
/tmux
between logging in and startingmyprocess
. Then detach from it withprefix
,d
.screen
's prefix isCtrl-A
, whiletmux
's prefix isCtrl-B
. You can log out but as long as the machine stays up, yourscreen
/tmux
session will too. Next time you log in, you can reattach thescreen
/tmux
shell, viascreen -r
ortmux attach
. -
Troyseph over 5 years
-
-
Adam Hunyadi almost 7 yearstail -f is cool, unfortunately mine fails to display control characters properly
-
Prajwel over 4 yearsIf you would like to change the nohup.out to something else, say run.log, and then follow it, use nohup myprocess > run.log 2>&1 & tail -f run.log