1752660 Members
5404 Online
108788 Solutions
New Discussion юеВ

Re: File Find

 
Mike Van Hoff
Occasional Contributor

File Find

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.
Life is ...
3 REPLIES 3
Bill Hassell
Honored Contributor

Re: File Find

The find command has the ability to locate files newer than the timestamp on a reference file. Simply use touch to create a dummy (zero-length) file that is 15 minutes old, then use i

find -newer -name '*out.out'

Note that find (unlike most commands) knows about pattern matching so escape the shell's expansion using single quotes.


Bill Hassell, sysadmin
Mike Van Hoff
Occasional Contributor

Re: File Find

But that does not answer the timing issues. I do not want to research the same dir. every 15 minutes? Any suggestions on doing this?
Life is ...
James A. Donovan
Honored Contributor

Re: File Find

"perl -le 'print scalar localtime time - 900'"

will give you the current time - 15 minutes.

...combine that with a recursive check of the time stamps of your directories, and you should be able to find any files that have been created within 15 minutes of your running the script.
Remember, wherever you go, there you are...