1

I want to use nohup and redirect stdout to a file but I do not need a archive I just want to be able to interactively view the current stdout. I am thinking I can redirect the stdout to a file to for it to be flushed after each output

??? nohup ruby myapp.rb > output.log &

interactly view the output tail -F ./output.log

veccy
  • 925
  • 3
  • 12
  • 20
  • You'll need to be more clear on that. If I correctly understand your problem, the commands you posted do exactly what you want. `tail -f` is designed to let you see what is *currently* happening in your log file. – racic Sep 30 '11 at 14:15
  • also, what kind of output is your ruby script producing? Does this output data describe a state of your program and you want to see only the latest state update? – racic Sep 30 '11 at 14:24
  • What my goal is to avoid the log file becoming to large, the app is saving to db at the end of the task this logging is just for live monitoring. So I am wondering if overwriting the log file each time is a good idea and if so how do I do it. The tail command does the job of viewing the file live but I notice it takes a few moments and updates multiple lines at a time and not a line at a time – veccy Sep 30 '11 at 15:42
  • The stdout from the ruby app is only output from the puts commands at each various steps in the program and yes it is only the latest state update – veccy Sep 30 '11 at 15:44
  • Avoiding large log file can be addressed by rotating your logs via the `logrotate` program. If you want to monitor the size of your log file you can do so programmatically in your ruby app and then log directly to a file (you'd have to implement a kind of internal logrotate in your prog). If you don't care about loss of some historic data in your log take look at my answer to this question. – racic Oct 01 '11 at 14:58

1 Answers1

1

You'll need to take a look at my answer to another question here: Linux non-blocking fifo (on demand logging).

Assuming that by now you've got the ftee program ready, if you call your app like this:

$ mkfifo /tmp/mylog

$ nohup ruby myapp.rb 2>&1 | tee output.log | ftee /tmp/mylog &

you'll get:

  • full output log int the file output.log
  • current output of your app available on demand via the /tmp/mylog fifo

Now if you want to just take a peek at your prog's latest output do:

$ cat /tmp/mylog

Hope this helps.

Community
  • 1
  • 1
racic
  • 1,235
  • 11
  • 20