리눅스 분류
아파치 로그의 404코드값을 가진 로케이션들의 카운트
작성자 정보
- 최광민 작성
- 작성일
컨텐츠 정보
- 3,351 조회
- 0 추천
- 목록
본문
우선 제가 간단히 작성한 스크립트는 이렇습니다.
#!/bin/bash
LOGHOME=/var/log/httpd
LOGFILE=/var/log/httpd/access_log
ERRORCODE5=`cat $LOGHOME/access_log | grep 404 | awk '{print $7}' | sort -u`
echo "Access Log Check now"
echo ""
echo "################### This is ERROR CODE 404 ##################"
echo ""
for LIST in $ERRORCODE5
do
echo "error code 404 list is -> $LIST"
echo -n "error total is -> "
cat $LOGFILE | grep 404 | grep $LIST | wc -l
echo ""
done
echo "#############################################################"
echo ""
이 스크립트의 결과값은 이렇습니다.
[root@Asianux2 ~/bin]# sh error_check
Access Log Check now
################### This is ERROR CODE 404 ##################
error code 404 list is -> /ckm.jsp
error total is -> 12
error code 404 list is -> /ckm2222.jsp
error total is -> 10
error code 404 list is -> /favicon.ico
error total is -> 3
error code 404 list is -> /index
error total is -> 4
error code 404 list is -> /index.html
error total is -> 3
error code 404 list is -> /test
error total is -> 3
error code 404 list is -> /test.jsp
error total is -> 1
error code 404 list is -> /test/
error total is -> 1
#############################################################
[root@Asianux2 ~/bin]#
하지만 이 스크립트에는 치명적인 문제점이 있습니다.
이를 테면 다음과 같이 access_log 의 7번째 필드는 로케이션 값이고 9번째 필드는 에러코드 값입니다.
192.168.122.1 - - [17/Aug/2007:02:13:03 +0900] "GET /ckm.jsp HTTP/1.1" 404 286 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; ko; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
이중 9번째 필드에 404 값이 있는 파일만을 추출해야 하는데...
현재의 스크립트로서는 전체 열에서 404를 찾게 됩니다.
아무리 생각해도 답이 않나오네요.. 도와주세요 ㅠㅠ
원하는 로직은 아파치 로그의 9번째 필드 즉 에어코드 필드에서 404값이 있는 행만을 추출하여 그 행의 7번째 필드인 로케이션을 추출하고 그 로케이션값을 가진 행들중 동일한 404값을 가진 행들의 전체 카운트를 다시 뽑아내는 겁니다.
awk 와 wc -l , sort , xargs 등을 이용하면 어떻게 될것 같은데.. 도저히 감이 안오네요..
#!/bin/bash
LOGHOME=/var/log/httpd
LOGFILE=/var/log/httpd/access_log
ERRORCODE5=`cat $LOGHOME/access_log | grep 404 | awk '{print $7}' | sort -u`
echo "Access Log Check now"
echo ""
echo "################### This is ERROR CODE 404 ##################"
echo ""
for LIST in $ERRORCODE5
do
echo "error code 404 list is -> $LIST"
echo -n "error total is -> "
cat $LOGFILE | grep 404 | grep $LIST | wc -l
echo ""
done
echo "#############################################################"
echo ""
이 스크립트의 결과값은 이렇습니다.
[root@Asianux2 ~/bin]# sh error_check
Access Log Check now
################### This is ERROR CODE 404 ##################
error code 404 list is -> /ckm.jsp
error total is -> 12
error code 404 list is -> /ckm2222.jsp
error total is -> 10
error code 404 list is -> /favicon.ico
error total is -> 3
error code 404 list is -> /index
error total is -> 4
error code 404 list is -> /index.html
error total is -> 3
error code 404 list is -> /test
error total is -> 3
error code 404 list is -> /test.jsp
error total is -> 1
error code 404 list is -> /test/
error total is -> 1
#############################################################
[root@Asianux2 ~/bin]#
하지만 이 스크립트에는 치명적인 문제점이 있습니다.
이를 테면 다음과 같이 access_log 의 7번째 필드는 로케이션 값이고 9번째 필드는 에러코드 값입니다.
192.168.122.1 - - [17/Aug/2007:02:13:03 +0900] "GET /ckm.jsp HTTP/1.1" 404 286 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; ko; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
이중 9번째 필드에 404 값이 있는 파일만을 추출해야 하는데...
현재의 스크립트로서는 전체 열에서 404를 찾게 됩니다.
아무리 생각해도 답이 않나오네요.. 도와주세요 ㅠㅠ
원하는 로직은 아파치 로그의 9번째 필드 즉 에어코드 필드에서 404값이 있는 행만을 추출하여 그 행의 7번째 필드인 로케이션을 추출하고 그 로케이션값을 가진 행들중 동일한 404값을 가진 행들의 전체 카운트를 다시 뽑아내는 겁니다.
awk 와 wc -l , sort , xargs 등을 이용하면 어떻게 될것 같은데.. 도저히 감이 안오네요..
관련자료
-
이전
-
다음
댓글 0
등록된 댓글이 없습니다.