parsing - Shell Script to get exception from logs for last one hour -
I am developing a script that will log the log of the last hour and check any exceptions and the solar system Will send emails for the platform.
I followed the following steps
grep -n -h date + '% Y-% m-% d% H:% M' test.logs The above command gives me the line number and then I do the following
tail + 6183313 test.log | Grep 'Exception' Sample log
2014-02-17 10: 15: 02,625 | Warning | M: // DeadPoint | OSCMOD | 262 - Com. SMSP-Client - 0.0.0.R2D03-SNAPSHOT | 1201 or 101 has been refunded as an exception code from SP, but it has not been noticed on 2014-02-17 10:15: 02,625 warning. M: // DeadPoint | OSCMOD | 262 - Com. SMSP-Client - 0.0.0.R2D03-SNAPSHOT | Ignore the SP error and counterfeit success 2014-02-17 10:15: 02,626 | Information | 354466740-102951 | Serviceful 183 - org.apache.cxf | Outbound Message Please suggest any better options for working above.
with GNU date , you can use one: grep "^ $ (date-d-1hour + '% y-% m-% d% h')" Test.logs | | Grep 'Exception' | Exception in the last hour of "Mail-S" test.logs. "The first step above is to select all the log entries from the last hour. This is done by looking at all the rows starting from year-month-day and hour matching one month ago with grep : grep "^ $ (Date - D-1Hour + '% Y-% m-% d% H') "test.logs The next step in the pipeline is to select those exceptions from these lines :
grep 'exception' The last step in the pipeline is to send mail:
mail - S " Exceptions in the last hour of test.logs "Imran Razakhan Emraan Razakha above No mails (or the email address you chose) with the subject line "Exception logs in the last hour of the exam".
The -d option should not be underestimated by the date option. It may seem simple to subtract 1 from the present time, but if the present time is 12:00, then we need to adjust both day and time. If the first month of the month was 12:00, then we have to change the month too. And similarly for the year Optimization for Solaris:
Consider three cases:
-
Solaris 11 or better Under, GNU is available on the utility / usr / gnu / bin / date . Thus, we need to simply specify the path for the date : grep "$ $ (/ usr / gnu / bin / date -d - 1hour + '% Y -% m-% d% H') "test.logs | | Grep 'Exception' | Mail- "Exception in the last hour of test.logs" Emraan Razakhan -
Anyone can download 10 or more before Solaris & amp; Install GNU Date
-
If the date of GNU is still not available, then we have to find another way to find the date and time of one hour earlier. The simplest solution is the possibility of choosing a timezone that is one hour behind your timezone if it was time zone, then say, Hong Kong, then use:
grep "^ $ (TZ = Hong Kong) Date + '% Y-% m-% d% H') "test.logs | Grep 'Exception' | Mail- "Exception in the last hour of test.logs" Imran Razakhan
Comments
Post a Comment