Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2008
    Posts
    24

    Question Unanswered: Extracting patterns from a log file

    I want to extract Date,Time and Error (ORA-) from error log file as given below.

    Sun Apr 28 11:56:56 2008
    ORA-01555 caused by SQL statement below (Query Duration=26748 sec)
    Wed Apr 29 00:07:33 2008
    Completed checkpoint up to ABC [0x15295.2.10], SCN: 0x089e.b4b72add
    Wed Apr 29 00:09:48 2008
    Beginning log switch checkpoint up to ABC [0x15296.2.10], SCN: 0x045489e.b62bsdd10f6
    Wed Apr 29 02:51:58 2008
    ORA-000060: Deadlock detected. More info in file /dborafiles/abc/QCDE/admin/udump/aaa_ora_20389.trc.
    Wed Apr 29 03:08:32 2008
    ABBRC1: Evaluating archive log 3 thread 1 sequence 86703

    Need to extract errors(ORA-) and date,time in daily basis.
    I cann't use "grep -A/B" as using Solaris-9.

    Pls suggest me.

    Thanks,
    gohappy

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Code:
    awk '{ if ($1 ~ /^ORA-/) { print $prev_line" "$0; } $prev_line=$0; }' log_file
    You can tighten up the code a bit if you want but it works fine with the example file you supply. You'll need to change log_file to be the name of your log file.

    Mike

  3. #3
    Join Date
    Apr 2008
    Posts
    24
    Hi Mike,

    Thanks a lot. It's working perfect. Could u pls explain how the script finds today's date.

    Thanks,
    gohappy

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    it doesn't know anything about today's date!

    Code:
    awk automatically reads each line into $0
    
          if $0 starts with ORA- then
                print the previous line ($prev_line) and the current line.
    
          set $prev_line = current line
    It's quite simple logic but I should of laid it out better. I should also of initialised $prev_line but I'll leave that up to you if you wish (google for awk BEGIN).

    Mike

  5. #5
    Join Date
    Apr 2008
    Posts
    24
    Thanks Mike for your helping hand ......actually I have to extract the ORA- error datewise.....the log_file contents many errors with old dates and it's updated everyday ....... I have to run the script every day so that it extracts the ORA- errors for the current date......

  6. #6
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Depends on the size of your log file - if it's medium size then I'd just run the above and then grep the output for the current date. If it's a very very large file then you could tail the last 10000 lines and then run as above, greping for the current date again.

    Mike

  7. #7
    Join Date
    Apr 2008
    Posts
    24
    That's true......but it is difficult to grep both ORA- and current date combilely.If I put tail -1000f then it shows many old dated errors.As I am having 17 different log_files and have to extract the errors (ORA-) from each file. Trying to extract the error datewise means when I will run the script it will show the ORA- for current day. I have to make a daily Error Report for all 17 the log_files.

    Can we put a current date as input to this script so that it will find only today's ORA- errors .

    Thanks,
    gohappy

  8. #8
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quite possibly - here's a good tutorial on awk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •