1

I want to monitor nginx access.log for malformed requests and notify myself about such cases.

To do this i have written following command:

tail -n0 -f access.log | grep --line-buffered '\{' | xargs sentry-cly -m

But this solution doesn't work for some reason. If i remove last pipe and end with grep only - i will see output as log file get new records.

I don't understand why xargs not executed. It will be the same if you replace sentry-cli with cat or echo.

Could you clarify why I have such behavior?

1

By default, xargs collects input until it has as much as it thinks it can safely pass to a single invocation of the utility (in this case sentry-cly -m). That means it'll wait until it's seen a large number of log messages, then run sentry-cly -m first message second message third message ... thousandth message .... To avoid this, use xargs -L1 sentry-cly -m -- the -L1 tells it to runsentry-cly -m for every line it reads (i.e. for each message).

(Similarly, xargs -L2 sentry-cly -m would wait until it'd gotten 2 messages then run sentry-cly -m "firstmessage" "secondmessage", then wait for the next two... You can see this by running xargs -L2 echo, and then typing lines into it and watching what gets echoed when.)

1

After some further investigation I found that following solution works: xargs -L 1.

  • 1
    Thanks for closing the loop on your question. Can you add a sentence to explain what that does and clarify whether that is the entire command? – fixer1234 Dec 10 '16 at 22:25
  • Gordon already provided a good exmplanation – pro100sanya Dec 12 '16 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.