home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1669 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  1.6 KB

  1. From: tchrist@convex.COM (Tom Christiansen)
  2. Newsgroups: comp.unix.questions,alt.sources
  3. Subject: Re: Recursion without -R
  4. Message-ID: <104905@convex.convex.com>
  5. Date: 14 Aug 90 20:33:55 GMT
  6.  
  7. In article <494@llnl.LLNL.GOV> rjshaw@ramius.llnl.gov writes:
  8. >What are some quick tricks for getting programs like chmod and chown to
  9. >descend into all subdirectories? Programs without a -R option, that is.
  10.  
  11. Well, here's a quick way to change all files from a set of old uids and
  12. gids to new ones.  In this example, I want to change group uucp to be
  13. 1789, group staff to be 666, user kirk to be 1000, and user bill to be
  14. 7777.  This code traverses the file system making those changes, omitting
  15. NFS decents.
  16.  
  17. This is just a fragment of a larger program that does a lot of other 
  18. sanity checks and configuration stuff not included here.
  19.  
  20.     #!/usr/bin/perl
  21.  
  22.     $start = '/';         # do whole tree
  23.  
  24.     %nuid = ( 'kirk',    1000,
  25.           'bill',    7777 );
  26.  
  27.     %ngid = ( 'staff',     666,
  28.           'uucp',  1789  );
  29.  
  30.     open(FIND, "find $start \\( -fstype nfs -prune \\) -o -ls |");
  31.  
  32.     while (<FIND>) {
  33.     split;
  34.     $uid = $gid = -1;
  35.     ($file, $user, $group) = ($_[11], $_[5], $_[6]);
  36.     if (defined $nuid{$user})  { $uid = $nuid{$user}; }
  37.     if (defined $ngid{$group}) { $gid = $ngid{$group}; }
  38.     if (($uid != -1 || $gid != -1) && !chown($uid, $gid, $file))
  39.         { warn "$0: couldn't change $file to $uid.$gid: $!\n"; }
  40.     }
  41.  
  42.  
  43. --tom
  44. --
  45.  
  46.     Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
  47.     Convex Computer Corporation                            tchrist@convex.COM
  48.          "EMACS belongs in <sys/errno.h>: Editor too big!"
  49.