[완료] [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 명령 하나에 여러가지 치환 조건을 줄 수 있는지도 궁금하고요.
감사합니다.
unbuffered 옵션을 추가했더니 원하는 결과가 출력되네요.
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) 옵션이 정확히 어떤 일을 하는건지 설명을 봐도 이해가 안되네요.
도움 부탁 드려요. 감사합니다.
음 ..
그냥 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 옵션을 이용해도 원하는 결과를 얻을 수 있네요.
감사합니다.
댓글 달기