8

I have a project I'm working on, where a piece of Hardware is producing output that is continuously being written into a textfile. What I need to do is to stream that file as it's being written over a simple tcp/ip connection.

I'm currently trying to that through simple netcat, but netcat only sends the part of the file that is written at the time of execution. It doesn't continue to send the rest.

Right now I have a server listening to netcat on port 9000 (simply for test-purposes):

netcat -l 9000

And the send command is:

netcat localhost 9000 < c:\OUTPUTFILE

So in my understanding netcat should actually be streaming the file, but it simply stops once everything that existed at the beginning of the execution has been sent. It doesn't kill the connection, but simply stops sending new data.

How do I get it to stream the data continuously?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Grinner
  • 337
  • 7
  • 18

3 Answers3

11

Try:

tail -F /path/to/file | netcat localhost 9000
Freiheit
  • 8,408
  • 6
  • 59
  • 101
  • 2
    Yes, that sort of did it. I found tail in the win 2003 resource kit. Works like a charm. I changed the command to tail -f c:\out | netcat localhost 9000 Thanks! – Grinner Jun 03 '10 at 17:58
  • 3
    once a wise guy said, use -F instead of -f, as it will add the extra option to retry in case the service was restarted or new log was generated! – Waheed Oct 06 '18 at 07:52
  • This can't possibly work unless modified as described in @Grinner's comment (and should not have been marked accepted without that modification). `<` specifies that input should be read from a file named `tail`, not a *command* named `tail`. – Charles Duffy Jul 20 '19 at 20:51
  • Yall feel free to make an edit and adjust it as needed. – Freiheit Jul 20 '19 at 21:19
1

try:

tail /var/log/mail.log -f | nc -C xxx.xxx.xxx.xxx 9000
Zoe
  • 27,060
  • 21
  • 118
  • 148
Alexander
  • 11
  • 1
  • 1
    For bonus points it would be good to include some explanation of the code and why this solves the OP's problem. – SiKing Oct 17 '18 at 17:52
  • The `-f` should be **before** the filename to work with versions of `tail` that strictly comply with [POSIX utility syntax guidelines](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02) entry #9, which specifies that all options should precede operands. – Charles Duffy Jul 20 '19 at 20:55
-1

try nc:

# tail for get last text from file, then find the lines that has TEXT and then stream
# see documentation for nc, -l means create server, -k means not close when client disconnect, waits for anothers clients
tail -f  /output.log | grep "TEXT" | nc -l -k 2000
DarckBlezzer
  • 4,578
  • 1
  • 41
  • 51