File Search

I hope I can outline this clearly the first time. I have been asked to create a script to do the following:

Search a series of Directories that have been created withing 15 minutes of the current system time for a dynamic file name that ends in (dot)out .out.
If a file with that extension is found, search the file for the word "error".
If error is found, send an email to a data center operator.
If the word is NOT found, do nothing.

I believe I can handle items 3 and 4, but I am looking for help and suggestions in accomplishing item 1.
Thanks in Advance.

that's looking like your homeexercise!

# man find
# man fgrep
# man mail
# man if

pre�y

I don't agree that this sounds like homework. But I don't have enough information to help. Do you need to search the entire filesystem looking for recently created directories?

One could do this in php:

$path = "{whatever the path should be...}";
exec("slocate | grep $path | grep \".out\"", $results);

foreach($results as $file)
{
 if(filectime($file => (time() - 900)))
 {
    $fp = fopen($file);
    $test = fgets($file);
    if(gettype(ereg("error", $test)) != boolean)
      mail({do your thing...});
 }
}

erm... i forget if time() returns the epoch time stamp or not, but meh.

Thanks for the comments. First, this is NOT a homework exercise. Second I need to search for newly created directories below a specific path. This is a People Soft installation, and we are trying to automate the PI Run monitoring process.
Third, I am a novice Shell programmer, and know nothing about php. I have been trying to do this in a straight shell script because I think it makes better sense, but I am getting things out of syntax or something. Here's is what I have tried thus far.
###################################
find /opt/psoft/hr83tst/appserv/prcs/HRTST/log_output/AE_PI_* \
-type f \
-name '*.out' \
-exec grep -s error {} |mail -s"PI RUN Process Error" mikev@beverlycorp.com ';'\
-exec ls -ld {} ';'
###################################
Any suggestions?
Thanks in advance.

If you really mean what you said this is going to be very hard. Unix does not record creation time. What if a *.err suddenly appears in a directory that is one hour old? Is it really necessary to exclude it? If so, you need to create a list of pre-existing directories and test each candidate directory to see if it's on that list. And that list must have been prepared 15 minutes ago to satify your time requirement.

If you're willing tolerate being notified about newly arrived *.err files in old directories, you still have a similiar problem... no creation date. So you can't distinguish between a file that was created recently and one that was updated recently.

And your find statement does not seem to be worrying about these issues. Could it be a list of *.err files that recently had a write() is good enough?

Yes I am serious about the search. However, the directories needing searched are created each time the process runs success or failure. if I backup to the 'log_output' directory, the script above returns the expected results, but errors out when trying to send mail. The file name being sought in each sub-dir ends with 'out', if it contains the word 'error' the process was a failure. All other successful processes will NOT contain the word 'error'.

The email and some type of creation time for new directories/files is the issue with the above script/

You obviously know what you are talking about, so if you have any suggestions on how I might proceed, I would GREATLY appreciate it.
Thanks

I think you missed my point entirely. But I can at least help with that find statement. You're trying to do way too much with -exec. All you can do is exec a process. You can't pipe or do anything else that requires a shell. So switch to just -print when you find interesting files. And then do:

#! /usr/bin/ksh
find <whatever> -print | while read file ; do
         command involving $file
         another command involving $file
done
exit 0
#!/usr/bin/ksh
#----subtract 15 minutes (900 seconds) from time
STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 900);
printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')

#----create an empty file with a timestamp of 15 minutes ago
touch $STAMP /tmp/flagfile

#----find newer files
find /start/dir -type f -name '*.out' -newer /tmp/flagfile -print |\
while read FILE
do
  #----search the file for the word "error"
  if grep -q "error" $FILE
  then
    echo $FILE found, send an email to a data center operator
  fi
done

Thanks Ygor
This will do the trick nicely. remember when you use touch in this case you must precede the variable with a -t so that it uses the defined timestamp instead of the systime.

Thanks again!!!!