질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

쉘스트립스문의입니다.

작성자 정보

  • 한정희 작성
  • 작성일

컨텐츠 정보

본문

아무리 해봐도 모르겠어서 이것좀 이해할수있도록 도와주셧으면합니다

 

#!/bin/sh

# weberrors - scan through an Apache error_log file and report the
#    most important errors, then list additional entries.

temp="/tmp/$(basename $0).$$"

# the following three lines will need to be customized for your own
# installation for this script to work best.

htdocs="/usr/local/etc/httpd/htdocs/"
myhome="/usr/home/taylor/"
cgibin="/usr/local/etc/httpd/cgi-bin/"

sedstr="s/^/  /g;s|$htdocs|[htdocs]  |;s|$myhome|[homedir] |;s|$cgibin|[cgi-bin] |"

screen="(File does not exist|Invalid error redirect|premature EOF|Premature end of script|script not found)"

length=5                # entries per category to display

checkfor()
{
  grep "${2}:" "$1" | awk '{print $NF}' |
    sort | uniq -c | sort -rn | head -$length | sed "$sedstr" > $temp

  if [ $(wc -l < $temp) -gt 0 ] ; then
    echo ""
    echo "$2 errors:"
    cat $temp
  fi
}

trap "/bin/rm -f $temp" 0

if [ "$1" = "-l" ] ; then
  length=$2; shift 2
fi

if [ $# -ne 1 -o ! -r "$1" ] ; then
  echo "Usage: $(basename $0) [-l len] error_log" >&2
  exit 1
fi

echo Input file $1 has $(wc -l < "$1") entries.

start="$(grep -E '[.*:.*:.*]' "$1" | head -1 | awk '{print $1" "$2" "$3" "$4" "$5 }')"
end="$(grep -E '[.*:.*:.*]' "$1" | tail -1 | awk '{print $1" "$2" "$3" "$4" "$5 }')"
echo -n "Entries from $start to $end"

echo ""

### Check for various common and well-known errors:

checkfor "$1" "File does not exist"
checkfor "$1" "Invalid error redirection directive"
checkfor "$1" "premature EOF"
checkfor "$1" "script not found or unable to stat"
checkfor "$1" "Premature end of script headers"

grep -vE "$screen" "$1" | grep "[error]" | grep "[client " |
  sed 's/[error]/`/' | cut -d`  -f2 | cut -d  -f4- |
  sort | uniq -c | sort -rn | sed 's/^/  /' | head -$length > $temp

if [ $(wc -l < $temp) -gt 0 ] ; then
  echo ""
  echo "Additional error messages in log file:"
  cat $temp
fi

echo ""
echo "And non-error messages occurring in the log file:"

grep -vE "$screen" "$1" | grep -v "[error]" |
  sort | uniq -c | sort -rn |
  sed 's/^/  /' | head -$length

exit 0

 

부탁드입니다..

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,138 명
  • 현재 강좌수 :  36,196 개
  • 현재 접속자 :  586 명