[K12OSN] OT: bash scripting - check for permissions, check for existence of file in directory tree

Rob Owens rob.owens at biochemfluidics.com
Fri Sep 26 12:06:46 UTC 2008



Nils Breunese wrote:
> David Hopkins wrote:
> 
>> What about using the locate command (which is much faster) in a
>> script? And then testing if the command returned successfully, e.g.
>>
>> locate somefile
>> if [ $? -eq 0 ] then
>> # successfully located somefile
>> # operate on the file (or check that it is part of the correct
>> directory structure?)
>> fi
>>
>> $? returns the success/failure of the immediately preceding command.
>> and if run updatedb each night, locate will work for any but the most
>> recent files?
> 
> That works if the frequency at which your locate database is updated if
> good enough for your application. You could add an extra check to see if
> the file really exists after locate says it exists. You'll still miss
> files that were created after the last time your locate database was
> updated. If you want to have the most recent info about your filesystem
> you'll just have to stick with find.
> 
> I guess it also depends on whether the directory you're searching has a
> lot of files. If it's not too big it's probably not worth it to use
> locate and sacrifice precision.
> 
Thanks, that would probably be a good option for me too.  It would be a
rare case that we issue a drawing and then obsolete it in the same day
(and that's what this script is for -- obsoleting drawings).

This is what I've been using for the past couple of days in my testing:

if [ 'find $MASTERDIR -name $(basename $OLDREV)' ]; then
          stamp_and_move $OLDREV
else
          error-file_location
          exit
fi

-Rob
********************************************************

The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. If you are not the addressee, any disclosure, reproduction,
copying, distribution, or other dissemination or use of this transmission in
error please notify the sender immediately and then delete this e-mail.
E-mail transmission cannot be guaranteed to be secure or error free as
information could be intercepted, corrupted lost, destroyed, arrive late or
incomplete, or contain viruses.
The sender therefore does not accept liability for any errors or omissions
in the contents of this message which arise as a result of e-mail
transmission. If verification is required please request a hard copy
version.

********************************************************




More information about the K12OSN mailing list