Re: grep within files older than 3 days



Matt Williamson wrote:
I have a directory of log files that I want to check for completion times
but only if they're less than 3 days old.

This is under ksh on AIX 4.2

"find . -name '*.log' -mtime 3" lists all of the files but I can't figure
out how to pipe it to grep to search within each file for the string
"completed at". I've tried different combo's of using the -exec param of
find as well as just standard piping with xargs. I've not found a working
solution yet. Am I on the right track or should I do it a different way?

Matt,

The find command you are doing won't look at the contents of the log
files, but rather looks at the last modified time of each log file. I
think you will need to use the grep comamnd to search within each log
for the dates you are looking for.

Assuming that some logs are NOT updated daily, and that other logs are
only updated with completion times when the particular program is run,
I will suggest the following logic:

A) Find all log files NOT older than 3 days
B) grep inside these for completion times

Not knowing how big your files are, how many logs you have, or what the
format looks like inside, I am going to assume log files that look
similar to the one I listed below:

Backup on 06-Jun-10 started at 01:01:00
Backup on 06-Jun-10 completed with errors at 01:08:38
Backup on 06-Jun-11 started at 01:01:02
Backup on 06-Jun-11 completed normally at 03:14:19
Backup on 06-Jun-12 started at 01:01:00
Backup on 06-Jun-12 completed normally at 03:12:17

If the logs all end in .log, then you can try this:

# find . -name "*.log" ! -mtime +3 -print|grep "completed"

Or if you need the log filename:

# for LOOP in $(find . -name "*.log" ! -mtime +3 -print)
# do
# echo "Verification of log: ${LOOP}"
# grep "completed" ${LOOP}
# done

There are probably other ways to do this too, using xargs or awk or
some other command. I am curious to see what others some up with.

Steve

.



Relevant Pages

  • Search of Text
    ... Performed on log files. ... Please provide me the script or command to perform the desired action. ... I suppose the combination of find and grep should do the requisite. ...
    (AIX-L)
  • Re: FREE SYSADMIN SEARCH TOOL
    ... >> Here's the url I found to get Splunk for free. ... Grep is totally fine for small, simple, local files, but.. ... Does grep work on 20GB of log files? ... Does grep automatically find related events in your log files? ...
    (linux.redhat)
  • FINDSTR questions
    ... Looked so far in vain for a good grep command or GUI that will do this, ... (I'm in the current directory with all the .log files I'm searching for). ... Anyone a pro at this command? ...
    (microsoft.public.windowsxp.help_and_support)
  • FINDSTR question
    ... Looked so far in vain for a good grep command or GUI that will do this, ... (I'm in the current directory with all the .log files I'm searching for). ... Anyone a pro at this command? ...
    (microsoft.public.windowsxp.help_and_support)
  • FINDSTR question
    ... Looked so far in vain for a good grep command or GUI that will do this, ... (I'm in the current directory with all the .log files I'm searching for). ... Anyone a pro at this command? ...
    (microsoft.public.win2000.general)