0

I have netcat working between a debian system and mac osx, but I can't get debian system to send updates of a log file to the mac which is listening with:

nc -k -l 8888

But regardless of what I tried on the sending side with tail -f mylogfile | netcat machostip 8888 or watch tail -f etc nothing gets through to the other side. Each time logfile updates I'd like the data visible on the mac side...

Again I've tried many different ways of piping or redirect < using netcat but haven't managed to have it working. It does work fine if I do simple echo a command but doesn't work with tail -f watching a logfile...

nc -k -l 8888
tail -f mylogfile | netcat macip 8888

expect logfile updates piped over netcat to the mac.

Based on @CharlesDuffy input/response, I have verified he is correct and that it works, except that I was using tail -f mylogfile | grep "only this stuff" | netcat macip 8888.

So question now is can I somehow filter the tail -f output before piping2netcat?

jww
  • 97,681
  • 90
  • 411
  • 885
htfree
  • 331
  • 1
  • 15
  • If you aren't already familiar with [BashFAQ #9](https://mywiki.wooledge.org/BashFAQ/009), it's worth a read. To be clear, `tail -f somefile | nc macip 8888` works perfectly fine as-is, but as soon as you start adding components that do filtering (and use standard C library functions for buffered IO), things get more interesting. – Charles Duffy Jul 20 '19 at 20:49
  • @l'L'l, ...the accepted answer on that question can't possibly work. – Charles Duffy Jul 20 '19 at 20:50
  • @CharlesDuffy, oh I see; any particular reasoning for that? – l'L'l Jul 20 '19 at 20:51
  • 1
    @l'L'l, `foo < tail` is reading `tail` as an input file, not running `tail` as a program. The OP there specified in a comment that they had to change the answer before it worked; I'd argue that they shouldn't have accepted it until it was edited. – Charles Duffy Jul 20 '19 at 20:52
  • @CharlesDuffy you are right! it hadn't dawned on me that my simple grep messed it up – htfree Jul 20 '19 at 20:54
  • So it isn't possible to filter tail -f with grep or something else before piping to netcat? – htfree Jul 20 '19 at 20:55
  • @htfree, it's perfectly possible; read the BashFAQ link above. – Charles Duffy Jul 20 '19 at 20:56
  • @htfree, Post a new question about the filtering you mentioned. – l'L'l Jul 20 '19 at 20:58
  • @CharlesDuffy sorry I just finished updating question based on your input, im reading your link now thx – htfree Jul 20 '19 at 20:58
  • 1
    @l'L'l, no reason for a new question -- we already have questions on the topic; this is closed as a duplicate of one of them. :) -- and while edits that change a question's meaning are frowned on *after there are answers*, no answers yet on this Q, so the edit was fair game. – Charles Duffy Jul 20 '19 at 20:59
  • @CharlesDuffy awesome it works. Believe me I searched a LOT on google and never found solution or the link you sent me which solved my problem! – htfree Jul 20 '19 at 21:01
  • @htfree, glad this helped! Duplicates aren't a bad thing (so long as they use different terminology from the earlier version) -- if someone else's Google hit finds this question, and then they follow the "duplicate of..." link, then they just got an answer! :) – Charles Duffy Jul 20 '19 at 21:02
  • @CharlesDuffy if you post as answer I will accept your link as solution, its working well for me, tx again! – htfree Jul 20 '19 at 21:02
  • @CharlesDuffy yea a lot of times people assume we were lazy, but I was up for hours last night, searching solution, sure my brain was dead too :D – htfree Jul 20 '19 at 21:03
  • @htfree better to have a single canonical place for each question -- otherwise, it's just luck which instance a person finds when they're searching and how good the answers there are; funnel everyone with the same question to a single instance of that question, and that one instance can collect all the answers to get the best voting/editing/etc improving those answers' quality. At least, that's the idea. :) – Charles Duffy Jul 20 '19 at 21:26
  • 1
    @CharlesDuffy I agree with flagging Duplicates as a very GOOD thing and very "useful" since sometimes we want to see "variety" of similar answers. My point is that a solution to flagged duplicates is "desirable". Addition, instead of stdbuf -oL grep 'mystuff' , I found that grep --line-buffered also works but stdbuf may be better with commands without buffer option. Oh and they could allow an ANSWER but limit/prohibit voting/upvotes etc but its kinda like communism, why not capitalism decide which duplicate is best? – htfree Jul 20 '19 at 21:30

0 Answers0