스크립트가 실행될 때 업데이트되는 로그 파일이 있습니다. 스크립트는 시작될 때 "스크립트 시작" 텍스트를 삽입하고 끝날 때 "스크립트 종료" 텍스트를 삽입합니다. "스크립트 시작"과 "스크립트 끝" 사이의 텍스트를 캡처하려고 합니다. 최신 항목은 로그 하단에 있습니다.
다음을 사용하면 종료되지만 아래와 같이 로그의 모든 이벤트가 표시됩니다.
tac /opt/novell/JDBCFanout/activemqstatus.log |awk '/End of script/,/Start of script/'|tac
2014-09-09 12:30:42 - Start of script
2014-09-09 12:30:42 - Monitoring Reset script for the ActiveMQ.
2014-09-09 12:30:42 - The ActiveMQ value is not 1, the ActiveMQ services will not be restarted. The current value is 0.
2014-09-09 12:31:35 - The Fanout driver state is: 0
2014-09-09 12:33:32 - Sleeping for 10 seconds before checking the status of the Fanout driver.
2014-09-09 12:35:05 - The Fanout driver state is: 1
2014-09-09 12:35:05 - ERROR: The Fanout driver failed to start. The Fanout driver needs to be manually restarted.
2014-09-09 12:35:05 - End of script
2014-09-09 13:17:17 - Start of script
2014-09-09 13:17:17 - Reset script for the ActiveMQ.
2014-09-09 13:17:17 - The ActiveMQ flag is 1, shutting down the ActiveMQ services and the Fanout driver.
2014-09-09 13:17:17 - The ActiveMQ flag is now set to 0.
2014-09-09 13:17:17 - Stopping the Fanout driver.
2014-09-09 13:17:27 - The script is now cleaning up the pid's.
2014-09-09 13:17:37 - The script is now archiving the ActiveMQ Logs.
2014-09-09 13:17:37 - No files older than 60 days.
2014-09-09 13:17:47 - The script is now starting the ActiveMQ services.
2014-09-09 13:19:57 - The ActiveMQ service is running,
2014-09-09 13:19:57 - The ActiveMQ Oracle service is running.
2014-09-09 13:19:57 - The ActiveMQ MSSQL service is running.
2014-09-09 13:19:57 - The ActiveMQ Queue Manager service is running.
2014-09-09 13:19:58 - Sleeping for 10 seconds before checking the status of the Fanout driver.
2014-09-09 13:20:09 - The Fanout driver successfully restarted.
2014-09-09 13:20:09 - End of script
특히, 위에 표시된 대로 발생하는 모든 결과가 아닌 출력이 다음과 같이 나타나기를 원합니다.
2014-09-09 13:17:17 - Start of script
2014-09-09 13:17:17 - Reset script for the ActiveMQ.
2014-09-09 13:17:17 - The ActiveMQ flag is 1, shutting down the ActiveMQ services and the Fanout driver.
2014-09-09 13:17:17 - The ActiveMQ flag is now set to 0.
2014-09-09 13:17:17 - Stopping the Fanout driver.
2014-09-09 13:17:27 - The script is now cleaning up the pid's.
2014-09-09 13:17:37 - The script is now archiving the ActiveMQ Logs.
2014-09-09 13:17:37 - No files older than 60 days.
2014-09-09 13:17:47 - The script is now starting the ActiveMQ services.
2014-09-09 13:19:57 - The ActiveMQ service is running,
2014-09-09 13:19:57 - The ActiveMQ Oracle service is running.
2014-09-09 13:19:57 - The ActiveMQ MSSQL service is running.
2014-09-09 13:19:57 - The ActiveMQ Queue Manager service is running.
2014-09-09 13:19:58 - Sleeping for 10 seconds before checking the status of the Fanout driver.
2014-09-09 13:20:09 - The Fanout driver successfully restarted.
2014-09-09 13:20:09 - End of script
공유할 수 있는 도움에 미리 감사드립니다!
답변1
어쩌면 작은 상태 머신일 수도 있습니다.
tac file |
awk '/End of script/ {p=1} p {print} p && /Start of script/ {exit}' |
tac
답변2
Glenn의 답변보다 훨씬 간단합니다("스크립트 시작"을 두 번 입력해야 하지만).
음식물로그 파일awk '/스크립트 종료/,/스크립트 시작/{인쇄} /스크립트 시작/{종료}' |
또는
음식물로그 파일| sed -n '/스크립트 끝/,/스크립트 시작/p' |