1

I've been using below command to make tail to write nohup.out and also print the output on the terminal.

nohup train.py & tail -f nohup.out

However, I need nohup to use different file names.

When I try

nohup python train.py & tail -F vanila_v1.out

I'm getting following error message.

tail: cannot open 'vanila_v1.out' for readingnohup: ignoring input and appending output to 'nohup.out': No such file or directory

I also tried nohup python train.py & tail -F nohup.out > vanila_v1.txt

Then it doesn't write an output on stdout.

How do I make nohup to write other than nohup.out? I don't mind simultaneously writing two different files. But to keep track of different processes, I need the name to be different. Thanks.

aerin
  • 20,607
  • 28
  • 102
  • 140

1 Answers1

2

You need to pipe the STDOUT and STDERR for the nohup command like:

$ nohup python train.py > vanila_v1.out 2>&1 & tail -F vanila_v1.out

At this point, the process will go into the background and you can use tail -f vanila_v1.out. That's one way to do it.

A little more information is available here for the STDOUT and STDERR link. Here is another question that uses the tee command rather that > to achieve the same in one go.

aerin
  • 20,607
  • 28
  • 102
  • 140
darthsidious
  • 2,851
  • 3
  • 19
  • 30
  • Hi Thanks for the comment but when I try your command, it doesn't print out on stdout. – aerin Aug 09 '18 at 23:48
  • The reason why I used tail was to print out on stdout. – aerin Aug 09 '18 at 23:48
  • 3
    @Aaron The full command line would be `nohup python train.py > vanila_v1.out 2>&1 & tail -F vanila_v1.out`. There's a critical point here that I think you're missing: the parts before and after the `&` are *completely independent commands* (with the first being run in the background). Thus, you do the redirects for the first command as part of the first command, and have the second (`tail`) command read from wherever the first got redirected to. – Gordon Davisson Aug 10 '18 at 02:42