로그 파일을 추적하고 파악하여 한 줄로 결합하고 다른 명령에 인수로 전달하는 방법

로그 파일을 추적하고 파악하여 한 줄로 결합하고 다른 명령에 인수로 전달하는 방법

다음 명령을 사용하여 아래 오류 메시지(총 3줄)를 얻었습니다.

$ 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]

로그를 한 줄로 결합하는 몇 가지 기술을 시도하고 성공했습니다.

  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 " " - - -
    

telegram-notify다음으로 다음 명령을 사용하여 출력을 텔레그램으로 보내고 싶습니다 .

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

현재 제가 할 수 있는 최선은 xargs텔레그램을 사용하여 로그의 각 줄을 개별적으로 보내는 것입니다.

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

조언해주세요:

  1. 위에서 시도한 세 가지 xargs, , 명령 awk중 어떤 명령을 paste사용하여 줄을 결합해야 합니까?

  2. xargs//에서 명령 옵션으로 출력을 추가로 파이프하거나 전달하는 방법awkpastetelegram-notify--text

관련 정보