scripting help

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Thu Aug 2 19:33:53 UTC 2007


On Thu, Aug 02, 2007 at 02:52:21PM -0400, Neil Watson wrote:
> I want to check, in a script, for a file or files that are less than x
> number of days old.  If those conditions are met then do something.  I
> had something like this in mind:
> 
> find ${TOMCAT}build/backup -iname "*war_????????-????" \
>    -mtime -$BACKUPAGE || echo "No files found!"
> 
> However, I believe that if find encounters any errors, like permission
> denied, the exit value would change and the test would fail.
> 
> Can someone suggest a better way?

You just want to know if there are some or not?

change '|| echo ...' to '| wc -l'

Simple, then check if the result is 0 or higher.

Or use |grep -q '.' || echo ...

If grep sees anything, it returns true, otherwise it returns false.  No
files means no output so nothing for grep to match on.

--
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list