1

I have a binary file that is being written to continuously. I need to read the full content of that file to a pipe (either to nc or to a FIFO) and keep reading it while its is written (i.e. the receiver will not read EOF, but will block until more data is available).

How to do it? Is there a one line shell trick to do it?

lvella
  • 284
  • 2
  • 13

1 Answers1

3

Yes, it's called a named pipe. Check fifo(7) for a description and mkfifo(1) for usage and examples.

A possibly useless example just to demonstrate its ability to do what you ask.

On a terminal:

$ mkfifo named_pipe
$ ll named_pipe
prw-------. 1 dsastre dsastre 0 Nov 13 19:40 named_pipe|

$ while true; do dd if=/dev/urandom of=named_pipe bs=24; sleep 2; done

On other terminal:

$ while true; do head named_pipe | md5sum; sleep 2; done
ff2776ab01b610f700c1f055ded5aef0  -
76e5d5367cdf43be35c8bb61cce270a0  -
d86370714bbe28a903fc407d6822aee2  -
6d5f7e09f76d0ce12cfb72456eedec8f  -
dawud
  • 14,918
  • 3
  • 41
  • 61
  • I'm sorry, but this has little to do with what I meant (please help me clarify). I already know how to work with named pipes (or `fifo`s). The file I have is a normal file, and it is being continuously appended by a process. I want to send its contents to a fifo or a pipe so that the reader of that file descriptor never sees EOF, but instead blocks when no more data is available on the file... – lvella Nov 13 '15 at 20:17
  • Can you give some more detail about this reader program? what prevents the reader from stripping EOF and reading from the named pipe in a loop, for example? – dawud Nov 13 '15 at 20:43
  • If I read the ordinary file from the program, it will eventually find that the file is over and will terminate. If I read from a fifo (what I want), it will run for as long as the other end keeps feeding. Now, how can I make a fifo from this growing file? – lvella Nov 13 '15 at 21:12