24

I am using the bash shell. I frequently use nohup 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 to nohup.out.

Frequently, however, I would like to monitor the progress of my computation. I can do this by reading nohup.out using vi or tail, 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.

Andrew
  • 16,315
  • 34
  • 73
  • 77
  • 3
    Have you considered using `screen` or `tmux` instead of nohup? – derobert Sep 24 '12 at 21:21
  • @derobert Thanks. I have `screen` on my system, but I have never used it. I don't have `tmux` on my system, but I can try to get it. – Andrew Sep 24 '12 at 21:38
  • 2
    Just launch `screen`/`tmux` between logging in and starting `myprocess`. Then detach from it with `prefix`,`d`. `screen`'s prefix is `Ctrl-A`, while `tmux`'s prefix is `Ctrl-B`. You can log out but as long as the machine stays up, your `screen`/`tmux` session will too. Next time you log in, you can reattach the `screen`/`tmux` shell, via `screen -r` or `tmux attach`. – jw013 Sep 24 '12 at 21:46
  • https://serverfault.com/questions/414341/redirect-nohup-to-stdout – Troyseph Jan 23 '19 at 08:51

2 Answers2

24

You can run

nohup yourprocess & tail -f nohup.out
choroba
  • 45,735
  • 7
  • 84
  • 110
  • tail -f is cool, unfortunately mine fails to display control characters properly – Adam Hunyadi May 31 '17 at 10:37
  • If 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 – Prajwel Dec 12 '19 at 11:42
21

Proof.

nohup yourprocess 1>&2  | tee nohup.out &
Jhonathan
  • 3,525
  • 4
  • 24
  • 23