Re: grep within files older than 3 days
- From: "steven_nospam at Yahoo! Canada" <steven_nospam@xxxxxxxx>
- Date: 12 Jun 2006 11:21:25 -0700
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
.
- Follow-Ups:
- Re: grep within files older than 3 days
- From: Sverrir
- Re: grep within files older than 3 days
- References:
- grep within files older than 3 days
- From: Matt Williamson
- grep within files older than 3 days
- Prev by Date: Re: anybody has tried to install php with pear in AIX 5.3
- Next by Date: Re: Max File Size
- Previous by thread: Re: grep within files older than 3 days
- Next by thread: Re: grep within files older than 3 days
- Index(es):
Relevant Pages
|