Page 1 of 2

compare log file timestamp wth system date

Posted: 30 Apr 2013 04:12
by flaskvacuum
hi ,
i have a log file in this format:

Code: Select all

Tue Feb 05 12:35:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5520.trc.
Sun Mar 10 16:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5820.trc.
Thu Mar 14 18:25:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5940.trc.
Fri Mar 15 11:45:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5950.trc.
Sat Apr 27 17:30:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5999.trc.
Sun Apr 28 14:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6020.trc.
Mon Apr 29 17:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6620.trc.


lets say today date is -> Tue 04/30/2013, i only want to show 1 week old ORA-error from the log.

output:

Code: Select all

Sat Apr 27 17:30:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_5999.trc.
Sun Apr 28 14:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6020.trc.
Mon Apr 29 17:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6620.trc.


would appreciate if given some head start.

at the moment i am able to spilt the dd mm yy, but was concern how to work with things like leap year, some months that is of 29, 30, 31 days. Is there any function to do the comparing between the log file timestamp and system timestamp?

Code: Select all

set CurDate=13Jan2012
set yr=%Date:~-4,4%
set mth=%DATE:~-7,2%
set dte=%DATE:~-10,2%
if %mth% == 01 set mth=Jan
if %mth% == 02 set mth=Feb
if %mth% == 03 set mth=Mar
if %mth% == 04 set mth=Apr
if %mth% == 05 set mth=May
if %mth% == 06 set mth=Jun
if %mth% == 07 set mth=Jul
if %mth% == 08 set mth=Aug
if %mth% == 09 set mth=Sep
if %mth% == 10 set mth=Oct
if %mth% == 11 set mth=Nov
if %mth% == 12 set mth=Dec

set CurDate=%dte%%mth%%yr%

ECHO %CurDate%


Re: compare log file timestamp wth system date

Posted: 30 Apr 2013 05:31
by abc0502
how do you want to extract the data ?
for example, you enter a number that represent an amount of days let's say 22, and the batch will display the last 22 days.
is that what you need ?

or you want to enter a date in format DD/MM/YYYY, and how many days after or before that date to display ?

Hint:
you don't have to calculate the days in months or in years, use lines number instead.

Re: compare log file timestamp wth system date

Posted: 30 Apr 2013 05:42
by Squashman
Haven't you already started several other threads about this same topic?

Re: compare log file timestamp wth system date

Posted: 30 Apr 2013 06:59
by foxidrive
You haven't given enough feedback for anyone to want to try and help you further.

I asked you for a larger sample of the log file that we could download and figure out how to process - you didn't reply to me or to many other people's posts, but posted further posts and in various threads - and there was conflicting data in the mix. We just don't know what you are doing.

Re: compare log file timestamp wth system date

Posted: 01 May 2013 19:18
by flaskvacuum
Squashman wrote:Haven't you already started several other threads about this same topic?


no. since the previous is of different issue.

Re: compare log file timestamp wth system date

Posted: 01 May 2013 19:39
by flaskvacuum
abc0502 wrote:how do you want to extract the data ?
for example, you enter a number that represent an amount of days let's say 22, and the batch will display the last 22 days.
is that what you need ?

or you want to enter a date in format DD/MM/YYYY, and how many days after or before that date to display ?

Hint:
you don't have to calculate the days in months or in years, use lines number instead.


i guess is everytime the .bat is schedule to run lets say at 12am (once a month), it will get the system date and start to compare (before that date (system date) to display, past 7 days) with the timestamp of the log file.

Re: compare log file timestamp wth system date

Posted: 01 May 2013 21:20
by Endoro
foxidrive wrote:You haven't given enough feedback for anyone to want to try and help you further.

I asked you for a larger sample of the log file that we could download and figure out how to process

More input, please.

Re: compare log file timestamp wth system date

Posted: 01 May 2013 21:49
by flaskvacuum
Endoro wrote:
foxidrive wrote:You haven't given enough feedback for anyone to want to try and help you further.

I asked you for a larger sample of the log file that we could download and figure out how to process

More input, please.


do u really need it to be downloadable?

That is the exact log format i have.???

Re: compare log file timestamp wth system date

Posted: 02 May 2013 01:26
by Endoro
please provide more untouched real data.

Re: compare log file timestamp wth system date

Posted: 02 May 2013 01:59
by abc0502
one more question
Is it last seven days or last seven inputs?
I see here in your example missing days, os if you need last 7 days there could be only two entries in the past 7 days depending on current date

Edited:
And one more thing, in your cmd write:

Code: Select all

Echo %date%
and post the result here, we need your date format

Re: compare log file timestamp wth system date

Posted: 02 May 2013 02:49
by flaskvacuum
abc0502 wrote:one more question
Is it last seven days or last seven inputs?
I see here in your example missing days, os if you need last 7 days there could be only two entries in the past 7 days depending on current date

Edited:
And one more thing, in your cmd write:

Code: Select all

Echo %date%
and post the result here, we need your date format


my %date% output is:

Code: Select all

D:\testScripts>echo %date%
Thu 05/02/2013


yes, is past 7 days.
why it should be only 2 entires ? you mean the output is: ???

Code: Select all

Sun Apr 28 14:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6020.trc.
Mon Apr 29 17:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6620.trc.

Re: compare log file timestamp wth system date

Posted: 02 May 2013 02:59
by abc0502
flaskvacuum wrote:yes, is past 7 days.
why it should be only 2 entires ? you mean the output is: ???

Code: Select all

Sun Apr 28 14:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6020.trc.
Mon Apr 29 17:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6620.trc.

your sample log file ( first 3 ) doesn't have days in sequence, ( 5, 10, 14 ), that means it's not daily logs.
If we in day 30 and the last 7 logs is 29, 25, 20, 19, 18, 16, 15
if past 7 dayes it must be 29, 28, 27, 26, 25, 24, 23 but we only have 29, 25 so it will be only two.

did you post a random sample entries ?

Re: compare log file timestamp wth system date

Posted: 02 May 2013 03:17
by flaskvacuum
abc0502 wrote:
flaskvacuum wrote:yes, is past 7 days.
why it should be only 2 entires ? you mean the output is: ???

Code: Select all

Sun Apr 28 14:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6020.trc.
Mon Apr 29 17:15:31 SST 2013
ORA-00060: Deadlock detected. More info in file /opt/ora10g/admin/OCEANSIT/udump/oceansit_ora_6620.trc.

your sample log file ( first 3 ) doesn't have days in sequence, ( 5, 10, 14 ), that means it's not daily logs.
If we in day 30 and the last 7 logs is 29, 25, 20, 19, 18, 16, 15
if past 7 dayes it must be 29, 28, 27, 26, 25, 24, 23 but we only have 29, 25 so it will be only two.

did you post a random sample entries ?


your sample log file ( first 3 ) doesn't have days in sequence, ( 5, 10, 14 ), that means it's not daily logs.

yes is it not a daily logs. Sometime there will be daily. But lets take it as it will not be a daily logs.

If we in day 30 and the last 7 logs is 29, 25, 20, 19, 18, 16, 15
if past 7 dayes it must be 29, 28, 27, 26, 25, 24, 23 but we only have 29, 25 so it will be only two.


base on your logs written above, 29, 25, 19, 18, 16, 15
and if we are in day 30, with only the last 7days ago, yes only 29 and 25th records of ORA- error will be shown together with its timestamp.

did you post a random sample entries ?


i just extracted the log from the system on day 30th Apr.

Re: compare log file timestamp wth system date

Posted: 02 May 2013 06:11
by abc0502
I just wish it was just the last 7 logged days :lol: .

Try This, it's not 100% accurate, there might be a bout 4 days error less/more not sure as i treat all months as 30 days per month.

Code: Select all

@Echo OFF

SET "LogFile=Log.txt"
SET "PastDays=7"

Rem Get Day Name, Day, Year
SET "Day=%date:~7,2%"
SET "Month=%date:~4,2%"
SET "Year=%date:~10,4%"

Rem Get Current Day Number
SET /A CurrDayNum = ( Month * 30 ) + Day
SET /A AllowedNum = CurrdayNum - PastDays
echo current : %CurrDayNum%
echo Allowed : %AllowedNum%

Rem Read Log File and calculate day numbers for each
Rem And if the day number of an entry is less than or
Rem equla to AllowedNum we display it.

SET CountLine=0
SETLOCAL EnableDelayedExpansion
For /F "tokens=1-5* delims= " %%A In (' Type "%LogFile%" ') Do (
   SET /A CountLine = CountLine + 1
   SET "Line=%%A %%B %%C %%D %%E %%F"
   CALL :Process "%%B" "%%C"
   Rem We check for the number length, they must match in length to compare
   IF "!Result:~2,1!" == "" (
      SET "Result=0!Result!"
   )
   IF "!Result!" GTR "!AllowedNum!" echo !Line!
)

Pause
Exit

:Process
SET "MonthName=%~1"      // For Passed Month Name
SET "DayNumber=%~2"      // For Passed Day Number
SET "M=0"            // For Month Names
SET "N=1"            // For Month Number
Rem Note: The equal sign has no effect, like the space, it's just for visiual
For %%a In ( Jan=1 Feb=2 Mar=3 Apr=4 May=5 Jun=6 Jul=7 Aug=8 Sep=9 Oct=10 Nov=11 Dec=12 ) Do (
   SET /A N = N + 1
   SET /A M = M + 1
   IF /I "%MonthName%" == "%%a" (
      SET /A MonthNumber = N / 2
      SET /A Result = MonthNumber * 30 + DayNumber
   )
)
GOTO :EOF


Replace Line 32 with

Code: Select all

IF "!Result!" GTR "!AllowedNum!" echo !Line!>>"%outFile%"

and Add

Code: Select all

SET "OutFile=%Userprofile%\desktop\Result.log"
at line 5

That will get the result to an external file called Result.log at your desktop to see it better.

Re: compare log file timestamp wth system date

Posted: 02 May 2013 23:45
by Endoro
it seems as if no data can be obtained...