SUMMARY: "find" syntax question

From: Christopher L. Barnard (cbarnard@cs.uchicago.edu)
Date: Wed Dec 04 1996 - 15:56:10 CST


I asked:

> I'm trying to get the syntax right on this "find" command, and I'm
> hoping that someone else can see what I'm missing. I want this
> command to only look on local filesystems and ignore anything that
> is NFS mounted. "-mount" or "-xdev" don't work, because I want it
> to look on all of the local filesystems, not just /. "-local" doesn't
> seem to work properly, because this line
>
> /usr/bin/find / -local -name core -mtime +2 -print
>
> still generates lots of error messages about unreadable directories from
> NFS mounted directories that are not world readable. I don't see anything
> else in the man page that looks like what I want... Is there a way to
> do this without writing a script that parses the /etc/vfstab file for
> each local filesystem and then calls find individually with the -mount flag
> for each of these filesystems?

The suggestions:

Well, I got 25 responses, three of which worked. Suggestions included adding
these additional instructions to the find command:

-prune /net This unfortunately won't work because most of the filesystems
                that I wanted to prune are mounted from the auto.direct
                automounter map, so they don't show up in /net, or /stage,
                or /home, or anything nice and easy like that.

-mount instead of -local This doesn't work because it would only search
  or the filesystem in which it was started- in this
  -xdev for SunOS case /. I want it to search all local filesystems.

-fstype ufs This doesn't work because it will still try to look at
   or all of the files (to decide if they are on a ufs filesystem
  -fstype 4.2 or not) and what I'm trying to get rid of are the warnings
  for SunOS when it finds NFS-mounted non-world-readable files. This
                flag did not change that.

-fstype nfs -prune I had high hopes for this option. However, it still
                    didn't work; for some reason I do not understand, find
                    was able to determine that the auto_direct-mounted
                    filesystems were of type nfs, but it reported that
                    all of its subdirectories were of type ufs. This left
                    me back in the same point as "-fstype ufs", above.

use GNU find instead. Nope, didn't work. GNU find has the same problems.

and The Solution:

What this ends up requiring is a script, not just a single call to find.
The script reads through /etc/mnttab or /etc/vfstab looking for local
filesystems, and then calls find individually on each of those filesystems
(with -mount or -xdev to keep the find confined to that filesystem).
The three people who suggested something like this were Tony R McKenzie
<tonym@mround.bt.co.uk>, Chris Wozniak <KAW@wapet.com.au>, and Ernst-Gunar
Ortlepp <ortlepp@dkrz.de>. Chris and Ernst-Gunar gave me code fragments,
which I'll include here (summarized) for those who are interested. I went
with Chris' solution, but Ernst-Gunar's also worked for me in a mockup.

-----------
#!/bin/sh
#
# Author: Chris Wozniak
#
OSREV=`uname -r | cut -f 1 -d.`
#
# List mounted filesystems
if [ $OSREV -ge 5 ]; then
#
# on SunOS 5.x
     MNTLIST=`/usr/bin/grep ufs /etc/mnttab | awk '{print $2}'`
else
#
# on SunOS 4.x
     MNTLIST=`/bin/grep ' 4.2 ' /etc/mtab | awk '{print $2}'`
fi
#
# find and delete core files
for FSYS in $MNTLIST
do
     find $FSYS -name core -ctime +1 -xdev -exec rm -f {} \;
done
-----------
and
-----------
list=`df | grep /dev/dsk | awk '{print $1}'`
find $list -{what you want to do}
-----------

A final note: There appears to be a bit of confusion out there about find
(not that I'm surprised -- I was too). Since some of you may be relying on
a potentially broken find script, I wanted to draw attention to these two
points:

* Adding "-fstype ufs" does *not* stop find from looking at all of the
   files on any NFS mounted filesystems. It won't react to any thing it
   finds out there, but the find script is still taking the time to look
   at everything. On a busy server, this could be adding a significant
   amount of time to the find process.

* Adding "-mount" (or "-xdev" for SunOS) means that it will only look at
   the one filesystem in which the find command was started -- it does *not*
   look at all local filesystems.

Thanks to:

"Nicholas R LeRoy" <nleroy@norland.com>
Richard Snyder <rsnyder@eos.hitc.com>
"Plesha, Thomas A. (NSLC Pacific)" <TPlesha@seacosd.navy.mil>
"Mark `Hex' Hershberger" <mah@eecs.tulane.edu>
dhaut@level1.com (Dave Haut)
Dan Pritts <danno@fv.com>
wiles@geordi.calspan.com (Dale Wiles)
Thomas.P.Frohna@x400gw.ameritech.com
seanw@amgen.com
"Bruce Rossiter" <AROSSITE@us.oracle.com>
Tim Buller <buller@math.ukans.edu>
Mark Belanger <mjb@ltx.com>
bertins@db.erau.edu
bismark@alta.jpl.nasa.gov (Bismark Espinoza)
"Kevin P. Inscoe" <kpi@hobbes.crc.com>
"David Evans" <djve@deakin.edu.au>
Jochen Bern <bern@penthesilea.uni-trier.de>
Kevin.Sheehan@uniq.com.au (Kevin Sheehan {Consulting Poster Child})
erics@cimco.com (Eric M. Stone)
Chris Wozniak <KAW@wapet.com.au>
hxktb0@svho1nfs_1.supervalu.com (Kris Briscoe)
mjb@liffe.com
Tony R McKenzie <tonym@mround.bt.co.uk>
jbwendl@mtb.phil.mop.com (James Wendling)
ortlepp@dkrz.de (Ernst-Gunar Ortlepp)



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:17 CDT