[vox-tech] Shell Scripting Question

Mike Simons vox-tech@lists.lugod.org
Mon, 09 Jun 2003 13:29:58 -0400


--ZARJHfwaSJQLOEUz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jun 06, 2003 at 11:21:47AM -0700, Ken Herron wrote:
> --On Friday, June 06, 2003 10:34:36 -0700 Henry House=20
> >	find . -path '*/messages/*' -type f -print0 | xargs -0 chmod 777
>=20
> That's fine if the host has gnu find and xargs. If it doesn't,=20

=2E.. you could install them yourself and be done with that minor problem. =
 ;)


  _If_ the system has perl you and for whatever reason installing the
GNU findutils package is not okay, then I recommend you do it in perl and=
=20
not have to worry about weird characters or whitespace in the file names.=
=20

  I imagine a perl script it would also be a few times faster than a pure=
=20
shell script... the following should be functionally equivalent to Henry's
find.

  This script takes a list of directories to look in on the command line,
defaults to '/' if none are given.  Switch the comments on the change_file
function if you want to see what it would do without doing it.

    TTFN,
      Mike Simons

=3D=3D=3D=20
# sub change_file($) { print "chmod 0777, $_[0]\n"; }         # action to t=
ake
sub change_file($) { chmod 0777, $_[0] }                      # action to t=
ake

sub check_dir(@) {
  while ($dir =3D shift @_) {                               # for each dire=
ctory
    $dir .=3D "/" if $dir !~ m#^/$#;         # make sure a '/' is at end of=
 path
    $match =3D $dir =3D~ m#/messages/#;              # regular expression t=
o match

    opendir DIR, "$dir" or next;
    map { lstat "$dir$_";                       # figure out what type of f=
ile
          unshift @_, "$dir$_" if -d _ && $_ ne "." && $_ ne "..";  # add d=
irs
          change_file("$dir$_") if -f _ && $match; # change file if path ma=
tch
        } readdir DIR;
    closedir DIR;
  }
}

check_dir(@ARGV ? @ARGV : "/");               # arguments or '/' if none gi=
ven
=3D=3D=3D=20

--=20
GPG key: http://simons-clan.com/~msimons/gpg/msimons.asc
Fingerprint: 524D A726 77CB 62C9 4D56  8109 E10C 249F B7FA ACBE

--ZARJHfwaSJQLOEUz
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE+5MQW4Qwkn7f6rL4RAv++AKCQtgjXsmXgIKI06ZRbrqGoluWv4QCeO3q5
wV6tdRsQECssPkxxg6yWGYk=
=ibgl
-----END PGP SIGNATURE-----

--ZARJHfwaSJQLOEUz--