리눅스 역참조(후방참조(\1)) 어떻게 사용하는 건가요?
조회수 806회
Oct 8 21:40:00 cent unix_chkpwd[1480]: password check failed for user (user1)
Oct 8 21:40:00 cent sshd[1478]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=10.221.55.2 user=user1
Oct 8 21:40:02 cent sshd[1478]: Failed password for user1 from 10.211.55.2 port 53639 ssh2
Oct 8 21:40:05 cent sshd[1479]: Connection closed by 10.211.55.2
Oct 8 21:40:08 cent sshd[1478]: Failed password for user1 from 10.211.55.21 port 53655 ssh2
Oct 8 21:40:12 cent sshd[1478]: Failed password for user1 from 10.211.55.18 port 53619 ssh2
Oct 8 21:40:19 cent sshd[1478]: Failed password for user1 from 10.211.55.21 port 53655 ssh2
Oct 8 21:40:32 cent sshd[1478]: Failed password for user1 from 10.211.55.18 port 53619 ssh2
Oct 8 21:40:37 cent sshd[1478]: Failed password for user1 from 10.211.55.18 port 53619 ssh2
Oct 8 21:40:46 cent sshd[1478]: Failed password for user1 from 10.211.55.21 port 53655 ssh2
Oct 8 21:40:49 cent sshd[1479]: Connection closed by 10.211.55.21
Oct 8 21:40:52 cent sshd[1478]: Failed password for user1 from 10.211.55.18 port 53619 ssh2
Oct 8 21:40:55 cent sshd[1478]: Failed password for user1 from 10.211.55.18 port 53619 ssh2
Oct 8 21:41:02 cent sshd[1479]: Connection closed by 10.211.55.18
이런 내용이 있는 abc.log 파일에서 Failed password for user1 from
의 from 뒤에 오는 ip 주소만 출력하고 싶은데 "from (.*)" 와 역참조 \1를 사용하면 된다고 하더라고요. 그런데 이 \1 역참조를 어떻게 사용하는지 아무리 검색해도 잘 안 나와서 여기서 질문 올립니다.
sed -n '/Failed password for user1 from/p' abc.log
이게 Failed password for user1 from
가 포함된 라인만 출력하는 건데 여기서 어떻게 \1를 사용해야from 뒤에 있는 ip 주소만 출력되는지요?
또 Failed password for user1 from
가 너무 길어서 쉘 변수에 입력해서 사용하고 싶은데
SED_FAIL = "Failed password for user1 from"
이렇게 쉘 변수를 저장하는 게 맞을까요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력