On Wed, Feb 18, 2004 at 11:50:27PM +1100, Russell Coker wrote:
> If you are going to change such things then you need to use the -uid or -gid 
> options to find (depending on whether you are changing the UID or GID), and 
> you need to do it when the machine is in single-user mode (IE no-one can 
> login and cron jobs can't run).
> 

Hmmm.. I did say there was plenty of room for improvement, after all, 
obviously shell scripting is more prone to failure than a proper program 
in C but let's give it a shot:

----------------------------------------------------------
#!/bin/bash
set -e
DIR_TO_FIX=/home/groupX
GROUP=mygroup
PERM=g+rwX
VALIDUSERS="me|myself|other"

find $DIR_TO_FIX -type f -printf "%u %p\n" |
egrep "^$VALIDUSERS " |
while read user file
do
# Recheck the user and file, avoid races
  [ -e "$file" ] && {
   curuser=`ls -dl "$file" | awk '{ print $3 }'`
   [ "$curuser" = "$user" ] && {
          chown $GROUP "$file"
          chmod $PERM "$file"
   }
  }
done
---------------------------------------------------------

> It would be nice if someone was to patch the -R option of chown/chgrp/chmod 
> in 
> coreutils to do this sort of thing.

As an enhancement over the -h option? (to exclude hard links as 
well as symlinks)

Regards

Javi

Attachment: signature.asc
Description: Digital signature

Reply via email to