How to get the Logs between two Time Stamps?

Hi,

I have been working on the error Log script, where errors are pulled from server.

I need to pull the data of the error logs between two dates & time, for example :
22/12/2014 20:00:00
22/12/2014 22:00:00

Whatever error have came during this duration.
Now the question is the record which is stored in the path is having data as "Timestamp" keyword and i need to enter two time stamp, which will generate 2 files, i need the data between the duration.

Please show us a sample of the logs, give us sample starting and ending periods, and show us the output that should be produced from that input. Without seeing how timestamps are formatted in your logs and you telling us how we know which log entries are "errors" and which log entries are non-error log entries, we have little chance of guessing how to get you what you want.

Hi,

The code which is used to generate the logs is :

searchTerm="Application Code:"

tomcatServerList=("nt-fdsi-005513")
timestamp =$( date %H+%M+%S)
fileName=xyz_"$timestamp".txt

for i in "${tomcatServerList[@]}"
do
	logList=( `find /net/default.log*  -mtime -1` )
	for j in "${logList[@]}"
	do
		IFS=$'\n'
		resultsList=( "${resultsList[@]}" `grep -A2 "$searchTerm" $j| sed '/--/d'|grep -v "$searchTerm"`)
		
	done
done
  • This code is generating data for last 24 hours, i need get the logs for definite time duration, upon user input. And input sample is like :
22-12-2014 22:00:00
22-12-2014 23:42:00

It would be helpful if you can suggest some thing, if you require anything else let me know.

This code is not generating any output. Please post actual starting and ending period log samples.

Using a sortable date (eg: 2014-12-22) might also help.

I mostly agree with jlliagre. The code that you showed us will NOT produce any log files. It will, however, generate diagnostic output from the unknown command timestamp , from the invalid format string argument passed to the date command, or both. (But, if you ignore the diagnostics, it might not matter because $timestamp is never used.)

And, since $i is never used and there is exactly one element in the array tomcatServerList[] , the outer for loop in this script can be removed with no change in the acton of the inner for loop.

If you're unwilling to show us a (possibly sanitized) example of the data you're trying to process, we can't help you.

Hi,

I need to input 2 dates & time and get the log based on the time, i am able to get the logs for 24 hours using "mtime-1" for the file say xLOG in a directory.

I just need a code to get between two time periods

The sample Logs are stored in this time format:-
Timestamp: Mon Jan 12 01:59:53 EST 2015

You have been asked to provide a sample of a log file to be processed three times. You have repeatedly ignored that request. This thread is closed.