简体   繁体   中英

How can piping tail of a log to a script cause the process generating the log to stop generating entries?

I'm trying to solve a weird issue. I have evidence suggesting that the script I'm piping tail output to is the cause of the issue, but I'm not sure what to look for. Here's what I've got:

I have a java program that generates a log to stdout with which I merge stderr (2>&1) and redirect to a file. I run a separate shell script that does a tail -F that pipes it to a Perl script which operates on events in the log and never exits.

It's not the best design, but everything has worked for years until recently (the past couple months). There was an apparent problem with the jar file, as the log had built up tons of errors, so as a first step, I updated to the latest version. The new version however, in the setup I described above, stops adding entries to the log.

To narrow the issue, I have done the following:

tail -F log | perl -pne ‘$|=1;’
tail -F log

This shows that output continues to flow and suggests that something the script is doing is causing the problem.

However, that doesn't appear to be the whole story because when I run everything on a different computer, everything there works! It's only on a specific computer where the jar stops printing to the log.

Other details:

  • The java process continues to run in all cases.
  • I am testing by doing a tail -F again after running everything in the background
  • There may have been an OS update that caused the issue
  • Running in a bash shell
  • I updated a module that the perl script uses to be the same, but there is apparently a minor difference between the computer that it works on and the one that stops the java output which I have yet to investigate
  • Here are the actual commands I'm using for testing:
java -cp WemoServer.jar mpp.wemo.server.Headless -p 4033 -upnp -run -log >> WemoServer.log 2>&1 &
sh -c "tail -F WemoServer.log | ./WemoServerLogProcessor.pl -r rules.txt --extended" 2>&1 >> WemoParser.log &

#And I'm testing whether the java process stops generating output via:
tail -F WemoServer.log

I'm stumped as to how to debug this issue. What should I look for?

UPDATE: I have learned that the java process can still write to the log. I know this because if I leave it running long enough, and initial bonjour search function completes and writes a message stating as much to the log.

However, the moment I pipe a tail of the log to my script, it appears that event tries stop, such as is written when an outlet turns on or off or motion is detected. If I don't pipe the tail of the log to my Perl script, all device events get written to the log as they happen. It's as if the java process loses its communication ability with the devices.

I know that bonjour is used to discover the devices and it prints to the log their IP addresses, so I don't know what the interruption could be. My Perl script definitely does nothing with ports or bonjour or anything. It just parses a file on STDIN.

I suppose I can try updating the OS since it's 2 versions behind my laptop which works, but I'd like to understand what's going on.

I asked the wrong question. Yes, the output was stopping, but the stopping of the output happened to be catalyzed by connecting to the output stream. The ending of the output happens eventually even if left alone.

The real reason it was stopping is because I had 2 separate subscriptions to the Wemo device and it only supports 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM