로그파일 분석 스크립트 작성 좀 도와주세요..

kyeongchan의 이미지

로그파일을 분석해서 통계를 내려고 합니다.

로그파일 형태는
시:분:초 {INSERT|UPDATE} 입니다.

ex)
00:00:00 INSERT
00:00:01 UPDATE
00:00:01 INSERT
00:00:01 UPDATE
.
.
.
13:00:04 INSERT
13:05:04 INSERT
.
.
23:59:59 UPDATE

제가 뽑고 싶은 형태는
시간별 INSERT, UPDATE 개수입니다.

지금까지 한 방법은
시간별로 루프를 돌면서
grep "^시간" 로그명 | grep "INSERT" | wc -l
grep "^시간" 로그명 | grep "UPDATE" | wc -l

이런식이었습니다..

그러다 보니
파일하나 처리하는데 24번 파일을 오픈하는 결과가 나오더라구요..

이걸 파일 한번 쭉 읽어내려가면서 처리하고 끝내는 효율적인 방법을 고민하고 있습니다...

감사합니다..

IsExist의 이미지

php 로 짜 봤습니다.

<?

$fp = fopen("log", "r");
if ($fp) 
{
    while (!feof($fp)) 
    {
        $buf = fgets ($fp, 128);
        if (strlen ($buf) < 1) continue;
        list($tstr, $cstr) = split(' ', $buf);
        $cstr = trim ($cstr);
        $cnt[$cstr][$tstr]++;
    }
    fclose ($fp);

    $cstr_all = array_keys($cnt);
    for ($i = 0; $i < count($cstr_all); $i++) 
    {
        $tstr_all = array_keys($cnt[$cstr_all[$i]]);
        for ($j = 0; $j < count($tstr_all); $j++)
        {
            echo $cstr_all[$i] . " " . $tstr_all[$j] . " -> " . 
                $cnt[$cstr_all[$i]][$tstr_all[$j]] . "\n";
        }
    }
}

?>

---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

kyeongchan의 이미지

답변 잘 보았습니다..

PHP 말고 단순 SHELL 로는 안될까요..
환경이 지원을 안하네요...

kall의 이미지

awk '/^시간/{if($2=="UPDATE"){u++}if($2=="INSERT"){i++}};END{print "i:"i " u:"u}' 로그명

----
자신을 이길 수 있는자는
무슨짓이든 할수있다..
즉..무서운 넘이란 말이지 ^-_-^
나? 아직 멀었지 ㅠㅠ

익명 사용자의 이미지

로그분석하는 Gema 변환Rule

\A=@set{i;0}@repeat{24;@bind{@fill-right{00000000;$iINSERT};0}@bind{@fill-right{00000000;$iUPDATE};0}@incr{i}}
\Z=@set{i;0}@repeat{24;@fill-right{00;$i}시 @print_count{$iINSERT} @print_count{$iUPDATE} \n @incr{i}}
\N<N>\:<N>\:<N> <A>=@incr{$1$4}
print_count:<U>=@var{@fill-right{00000000;$1}}

http://bbs.kldp.org/viewtopic.php?t=57660&highlight=gema

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.