아래와 같은 로그 파일이 있습니다.
2017-05-30 23:11:34,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:34,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:34,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:34,453 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:33,673 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking logout agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,682 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Logout agent success [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,819 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.KeyboardInteractiveAuthentication - SSH: Sent SSH_MSG_USERAUTH_INFO_REQUEST (Password Authentication):
2017-05-30 23:11:33,871 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address /172.16.8.1:54626
2017-05-30 23:11:32,042 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:32,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,090 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,091 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:31,095 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:30,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:30,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:30,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:30,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:30,453 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:30,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:26,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:26,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:20,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:20,453 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:18,673 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking logout agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:18,682 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Logout agent success [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:15,819 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.KeyboardInteractiveAuthentication - SSH: Sent SSH_MSG_USERAUTH_INFO_REQUEST (Password Authentication):
2017-05-30 23:11:15,871 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address /172.16.8.1:54626
2017-05-30 23:11:14,042 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:14,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:12,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:11,090 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:10,091 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:09,095 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:09,415 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address gateway/172.16.8.1:54626
2017-05-30 23:10:59,416 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:10:42,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:10:35,429 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:10:30,438 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
sed
시작 검색 문자열을 사용하여 로그 파일을 검색 하고 싶습니다. Invoking logout agent
검색 끝 문자열은 입니다 Failed login attempt
. 조건이 일치하면 이러한 검색 문자열 사이의 정보를 반환합니다. 따라서 로그의 다른 곳에 인쇄될 수 있으므로 여러 일치 기준이 반환될 수 있습니다. 하지만 예상대로 작동하도록 할 수는 없었지만 이전에 사용한 기간 내에 작동합니다. 이것은 나의 sed
필수 주장 입니다.
sed -n '/Invoking logout agent/,/Failed login attempt/p' 1min.txt
반환된 정보의 첫 번째 줄에 " "가 없기 때문에 전체 로그 파일 블록이 반환되는 것 같습니다 Invoking logout agent
. 거기에서 제대로 작동하지 않는다는 것을 알 수 있습니다. 내 문제가 무엇인지 알 수 있나요? 이것은 나에게 가장 필요한 로그 블록입니다.
2017-05-30 23:11:33,673 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking logout agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,682 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Logout agent success [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,819 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.KeyboardInteractiveAuthentication - SSH: Sent SSH_MSG_USERAUTH_INFO_REQUEST (Password Authentication):
2017-05-30 23:11:33,871 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address /172.16.8.1:54626
2017-05-30 23:11:32,042 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:32,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,090 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,091 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:31,095 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
답변1
sed해결책:
sed -n '/Invoking logout agent/{:a;N;/Failed login attempt/!ba;G;p;}' imin.txt
산출:
2017-05-30 23:11:33,673 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking logout agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,682 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Logout agent success [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:33,819 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.KeyboardInteractiveAuthentication - SSH: Sent SSH_MSG_USERAUTH_INFO_REQUEST (Password Authentication):
2017-05-30 23:11:33,871 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address /172.16.8.1:54626
2017-05-30 23:11:32,042 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:32,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,090 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:31,091 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:31,095 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
2017-05-30 23:11:18,673 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking logout agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:18,682 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Logout agent success [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:15,819 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.KeyboardInteractiveAuthentication - SSH: Sent SSH_MSG_USERAUTH_INFO_REQUEST (Password Authentication):
2017-05-30 23:11:15,871 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - User login attempt has been made from address /172.16.8.1:54626
2017-05-30 23:11:14,042 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:14,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:12,072 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking config agent [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:11,090 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Config agent success [accountName=rene1 remoteAddress=gateway/172.16.8.1]
2017-05-30 23:11:10,091 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - Invoking auth agent [accountName=rene1 remoteAddress=STEDGE/172.16.8.3]
2017-05-30 23:11:09,095 INFO [SSHD-TRANSFER-1] com.tumbleweed.st.server.sshd.AuthenticationProviderImpl - SSH: Failed login attempt on [172.16.8.1]. Username: "rene1".
세부 사항:
/Invoking logout agent/
- 모든 만남 라인에서Invoking logout agent
:a;
- 라벨 정의a
N;
- 패턴 공간에 다음 줄을 추가합니다./Failed login attempt/!ba;
- 패턴 공간에 다음이 포함되어 있지 않은 경우Failed login attempt
- 태그로 다시 이동a
G
- 가독성을 높이기 위해 각 일치 항목 뒤에 줄바꿈을 추가합니다.p
- 인쇄 패턴 공간