Unix questions - question about find

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > September 2006 > question about find





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author question about find
nprashanth@gmail.com

2006-09-25, 1:27 pm

I have the following script to delete some log files:

1 #! /usr/bin/ksh

2 #delete collection files
3 LogCollDir=/data/
4 BackUpDays=3
5 FilePref=collection.log
6 nice -19 find ${LogCollDir} -name "${FilePref}.??????????" -mtime
+${BackUpDays} -exec rm -f {} \; &
7
8 #Remove old activity log files.
9 #Only the most recent one is left
10 ActLog=/data/act_*.log
11 nice -19 ls -t ${ActLog} | nawk '{ if ( NR != 1 ) { system("rm -f "
$0) } }'&

The script runs every night and sometimes I get an error like:
find: stat() error /data/act_09-22-2006.log: No such file or directory

The reason might be that in line 11, the script deletes the files which
start with act_, except the latest file, and in line 6 'find' reads the
same directory and does not find the file. But the command on line 6 is
supposed to find only those files which start with collection.log. Does
'find' run stat on all the files and try to match the name with the
regular expression afterwards? I can't think of any other scenario in
which this might happen.

Thanks for your help,
Prashanth.

Stephane CHAZELAS

2006-09-25, 7:34 pm

2006-09-25, 11:14(-07), nprashanth@gmail.com:
[...]
> 6 nice -19 find ${LogCollDir} -name "${FilePref}.??????????" -mtime
> +${BackUpDays} -exec rm -f {} \; &

[...]
> supposed to find only those files which start with collection.log. Does
> 'find' run stat on all the files and try to match the name with the
> regular expression afterwards? I can't think of any other scenario in
> which this might happen.

[...]

Yes, find stat(2)s every file to find out whether they are
directories, in which case it descends into it, or not.

It may do some optimisations, though like looking at the number
of links of a directory to find out whether it may contain
subdirectories or not (a subdirectory generally increments the
number of links of a directory, because of its ".." entry), that
may cause files not to be stat(2)ed.

--
Stéphane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com