[완료] [SED] tail -f 출력 결과를 sed로 두 번 이상 치환 시 출력이 되지 않습니다.

자일자일의 이미지

안녕하세요.

Redhat Linux 5.7에서 tail을 이용하여 시스템 로그를 모니터링하는데
특정 문자열을 SED 이용하여 치환해야 합니다.

아래와 같이 tail -f 결과를 sed 이용하여 한 번 치환할 경우엔 치환된 내용이 잘 출력됩니다.

[root@node1.gfs2.com ~]$ tail -f /var/log/messages | sed -e 's/node1/AAAAA/'
Mar 28 11:03:41 AAAAA openais[3578]: [SYNC ] This node is within the primary component and will provide service.
Mar 28 11:03:41 AAAAA openais[3578]: [TOTEM] entering OPERATIONAL state.
Mar 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.131
Mar 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.132
Mar 28 11:03:41 AAAAA openais[3578]: [CPG ] got joinlist message from node 1
Mar 28 11:03:45 AAAAA kernel: dlm: got connection from 2
Mar 28 11:04:37 AAAAA kernel: device eth0 left promiscuous mode
Mar 29 04:02:05 AAAAA rhsmd: This system is missing one or more valid entitlement certificates. Please run subscription-manager for more information.
Mar 29 10:35:23 AAAAA ccsd[3568]: Update of cluster.conf complete (version 18 -> 19).
Mar 29 15:31:15 AAAAA ccsd[3568]: Update of cluster.conf complete (version 19 -> 21).

그런데 위 출력 결과에 sed 치환을 한번 더 적용하면 아무런 내용이 출력되지 않아요.
[root@node1.gfs2.com ~]$ tail -f /var/log/messages | sed -e 's/node1/AAAAA/' | sed -e 's/Mar/Feb/'
[root@node1.gfs2.com ~]$

헌데, tail -f 대신 tail -100, cat 등을 이용해서 테스트 해보면 정상적으로 출력이 되네요.
[root@node1.gfs2.com ~]$ tail -30 /var/log/messages | sed -e 's/node1/AAAAA/' | sed -e 's/Mar/Feb/'
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] Members Joined:
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] r(0) ip(192.168.1.132)
Feb 28 11:03:41 AAAAA openais[3578]: [SYNC ] This node is within the primary component and will provide service.
Feb 28 11:03:41 AAAAA openais[3578]: [TOTEM] entering OPERATIONAL state.
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.131
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.132
Feb 28 11:03:41 AAAAA openais[3578]: [CPG ] got joinlist message from node 1
Feb 28 11:03:45 AAAAA kernel: dlm: got connection from 2
Feb 28 11:04:37 AAAAA kernel: device eth0 left promiscuous mode
Feb 29 04:02:05 AAAAA rhsmd: This system is missing one or more valid entitlement certificates. Please run subscription-manager for more information.
Feb 29 10:35:23 AAAAA ccsd[3568]: Update of cluster.conf complete (version 18 -> 19).
Feb 29 15:31:15 AAAAA ccsd[3568]: Update of cluster.conf complete (version 19 -> 21).
[root@node1.gfs2.com ~]$

결국 tail -f를 이용해서 계속 파일을 읽으면서 sed로 두 번 이상 치환 시 내용이 정상적으로 출력되지 않는데요.
왜 이렇게 작동하는지 궁금합니다. 도움 부탁드려요.

추가로, sed 명령 하나에 여러가지 치환 조건을 줄 수 있는지도 궁금하고요.

감사합니다.

자일자일의 이미지

http://stackoverflow.com/questions/8103385/log-parsing-with-sed-or-grep

위 URL을 참고하여 --unbuffered 옵션을 적용했더니 출력되네요.
-u, --unbuffered
load minimal amounts of data from the input files and flush the output buffers more often

[root@node1.gfs2.com ~]$ tail -f /var/log/messages | sed -u -e 's/node1/AAAAA/' | sed -u -e 's/Mar/Feb/'
Feb 28 11:03:41 AAAAA openais[3578]: [SYNC ] This node is within the primary component and will provide service.
Feb 28 11:03:41 AAAAA openais[3578]: [TOTEM] entering OPERATIONAL state.
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.131
Feb 28 11:03:41 AAAAA openais[3578]: [CLM ] got nodejoin message 192.168.1.132
Feb 28 11:03:41 AAAAA openais[3578]: [CPG ] got joinlist message from node 1
Feb 28 11:03:45 AAAAA kernel: dlm: got connection from 2
Feb 28 11:04:37 AAAAA kernel: device eth0 left promiscuous mode
Feb 29 04:02:05 AAAAA rhsmd: This system is missing one or more valid entitlement certificates. Please run subscription-manager for more information.
Feb 29 10:35:23 AAAAA ccsd[3568]: Update of cluster.conf complete (version 18 -> 19).
Feb 29 15:31:15 AAAAA ccsd[3568]: Update of cluster.conf complete (version 19 -> 21).

헌데... -u(or --unbuffered) 옵션이 정확히 어떤 일을 하는건지 설명을 봐도 이해가 안되네요.
도움 부탁 드려요. 감사합니다.

ymir의 이미지

그냥 sed -e 's/../' -e 's/.../' 와 같이 -e 옵션을 연속으로 쓰시면 될겁니다.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

자일자일의 이미지

-e 옵션을 이용해도 원하는 결과를 얻을 수 있네요.

감사합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.