Using the following command, I managed to fetch error messages below (it's 3 lines).

$ tail -f -n 0 error.log | grep -A2 --line-buffered "Internal server error"
! @79884flo2 - Internal server error, for (GET) [/] ->

play.api.UnexpectedException: Unexpected exception[Missing: No configuration setting found for key init.default]

Tried few technique to combine the logs into a single line and successful:

  1. xargs

    tail -f -n 0 error.log | grep -A2 --line-buffered "error" | xargs -I @ printf "%s" "@"
  2. awk

    tail -f -n 0 error.log | grep -A2 --line-buffered "error" | awk '{ printf("%s ", $0); }'
  3. paste:

    tail -f -n 0 error.log | grep -A2 --line-buffered "error" | paste -d " " - - -

Next I want to send the output to telegram using telegram-notify command:

telegram-notify --error --title "<title>" --text "<output from above command goes here>"

The best I can do at the moment is to send each line of the logs separately using xargs to telegram.

tail -f -n 0 error.log | grep -A2 --line-buffered "error" | xargs -L 3 -I {} telegram-notify --error --title "<title>" --text "{}"

Would you please advise:

  1. Which command among the three xargs, awk, paste I've tried above should be used to combined lines?

  2. How to pipe further or pass output from the xargs/awk/paste to the telegram-notify command --text option

  • Did you try putting another xargs in front of the existing xargs - tail -f -n 0 error.log | grep -A2 --line-buffered "error" | xargs -I @ printf "%s" "@" | xargs -L 3 -I {} telegram-notify --error --title "" --text "{}" ? Does that meet your purpose ? – amisax Sep 11 '18 at 8:58
  • @amisax Yes I did and it didn't work. Didn't see any tail output and telegram-notify is not triggered – Rashidee Mohd Rashid Sep 11 '18 at 10:29

Your Answer

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

Browse other questions tagged or ask your own question.